#2840
Check if Strings Can be Made Equal With Operations II
specialist · 775 · lc medium +31 · verified · 56.1% accepted · 272 likes · top 50%
Description
Two strings s1 and s2, both of length n and containing only lowercase letters, are given. You may apply the following operation any number of times on either string:
- Choose indices i and j with i < j and j - i even, then swap those two characters.
Return true if the strings can be made equal, false otherwise.
Example 1:
Input: s1 = "abcdba", s2 = "cabdab"
Output: true
Explanation: We can apply the following operations on s1:
- Choose the indices i = 0, j = 2. The resulting string is s1 = "cbadba".
- Choose the indices i = 2, j = 4. The resulting string is s1 = "cbbdaa".
- Choose the indices i = 1, j = 5. The resulting string is s1 = "cabdab" = s2.
Example 2:
Input: s1 = "abe", s2 = "bea"
Output: false
Explanation: It is not possible to make the two strings equal.
Code
1
2
3