Check if Strings Can be Made Equal With Operations II

You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.

You can apply the following operation on any of the two strings any number of times:

  • Choose any two indices i and j such that i < j and the difference j - i is even, then swap the two characters at those indices in the string.

Return true if you can make the strings s1 and s2 equal, and false otherwise.

Example 1
Inputs1 = "abcdba", s2 = "cabdab"
Outputtrue
By swapping characters in s1 at indices with even differences, it can be transformed into "cabdab", which equals s2.
Example 2
Inputs1 = "abe", s2 = "bea"
Outputfalse
It is not possible to make the two strings equal.

Constraints

  • n == s1.length == s2.length
  • 1 <= n <= 10^5
  • s1 and s2 consist only of lowercase English letters.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate