#2839

Check if Strings Can be Made Equal With Operations I

pupil · 465 · lc easy +26 · verified · 47.8% accepted · 200 likes · top 33%

Description

Two strings s1 and s2, both of length 4 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 j - i = 2 and swap those two characters.

Return true if the strings can be made equal, false otherwise.

Example 1:

Input: s1 = "abcd", s2 = "cdab"
Output: true
Explanation: We can do the following operations on s1:
- Choose the indices i = 0, j = 2. The resulting string is s1 = "cbad".
- Choose the indices i = 1, j = 3. The resulting string is s1 = "cdab" = s2.

Example 2:

Input: s1 = "abcd", s2 = "dacb"
Output: false
Explanation: It is not possible to make the two strings equal.

Code

1
2
3