Check if Strings Can be Made Equal With Operations II - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
s1 = "abc", s2 = "bac"
›
Output:
false
💡 Note:
Even positions: s1 has 'a','c' vs s2 has 'b','c'. Different frequencies at even positions, so impossible to make equal.
Example 2 — Same Characters Different Order
$
Input:
s1 = "abcde", s2 = "caebd"
›
Output:
false
💡 Note:
Even positions: s1 has 'a','c','e' vs s2 has 'c','e','d'. Different frequencies, so impossible to make equal.
Example 3 — Already Equal
$
Input:
s1 = "abc", s2 = "abc"
›
Output:
true
💡 Note:
Strings are already equal, so no operations needed.
Constraints
- 1 ≤ n ≤ 105
- s1.length == s2.length == n
- s1 and s2 consist only of lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code