Ctrl K

Append Letters Until Anagrams

Medium
You get two strings, left and right. In one move you may append any letter to the end of either string. Letters cannot be removed or changed. Return the fewest moves after which the two strings are anagrams of each other, that is, they hold the same letters in the same quantities.
Example 1
left="star", right="rats" → 0

The strings already hold the same letters.

Example 2
left="apple", right="leap" → 1

right needs one more p, left needs nothing.

Example 3
left="xy", right="zz" → 4

Append zz to left and xy to right: 4 letters in total.

Constraints
  • 1 ≤ len(left), len(right) ≤ 2 · 10⁵
  • Both strings consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Hint for a Digit Guess MediumCharacters Grouped by Count MediumMost Searched Words MediumNo Twin Letters Side by Side MediumDomain Visit Rollup Medium
loading Python…
Input
left="star", right="rats"
Expected
0

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