Ctrl K

Swaps Two Steps Apart

Medium
You are given two strings first and second of the same length, made of lowercase English letters. In one move you pick either string and swap two of its characters whose positions are an even distance apart (for example, positions 1 and 5, or 0 and 2). You may make any number of moves, including none. Return true if such moves can make the two strings identical, and false otherwise.
Example 1
first="lemon", second="nomel" → True

In both strings the even positions hold l, m, n and the odd ones hold e and o, so rearranging within each group makes them equal.

Example 2
first="abab", second="baba" → False

A letter on an even position can never move to an odd one. first has two a's on even positions, second has two b's.

Constraints
  • 1 ≤ len(first) = len(second) ≤ 10⁵
  • Both strings contain only lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAnagram Buckets MediumCharacters Grouped by Count MediumA Subsequence of One Word Only MediumMost Searched Words MediumWord Grown Letter by Letter Medium
loading Python…
Input
first="lemon", second="nomel"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.