JuniorString

Check if Strings Can be Made Equal With Operations I

You are given two strings s1 and s2, both of length 4, 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 j - i = 2, 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 = "abcd", s2 = "cdab"
Outputtrue
By swapping indices 0 and 2 in s1 to get cbad, then swapping indices 1 and 3 to get cdab, s1 becomes equal to s2.
Example 2
Inputs1 = "abcd", s2 = "dacb"
Outputfalse
It is not possible to make the two strings equal.

Constraints

  • s1.length == s2.length == 4
  • s1 and s2 consist only of lowercase English letters.

Asked at 3 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