Leetcode Problem 2840. Check if Strings Can be Made Equal With Operations II

2840. Check if Strings Can be Made Equal With Operations II

Leetcode Solutions

Check if characters match at odd and even positions

  1. Initialize two lists to store characters from even indices (even1 and even2) and two lists to store characters from odd indices (odd1 and odd2).
  2. Iterate over the indices of s1 and s2.
    • If the index is even, append the character at that index from s1 to even1 and from s2 to even2.
    • If the index is odd, append the character at that index from s1 to odd1 and from s2 to odd2.
  3. Sort even1, even2, odd1, and odd2.
  4. Compare the sorted even1 with even2 and odd1 with odd2.
    • If both comparisons are equal, return true.
    • Otherwise, return false.
UML Thumbnail

Count characters at odd and even positions

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...