Ctrl K

Same Letters, Reshuffled

Easy
You get two strings first and second made of lowercase English letters. Check whether second can be obtained by rearranging the letters of first: every letter must occur the same number of times in both strings. Return True if it can, and False otherwise. Food for thought: what would change if the strings could hold any Unicode characters?
Example 1
first="listen", second="silent" → True

Both words use the same six letters, just in a different order.

Example 2
first="banana", second="bandana" → False

The second word has one letter more, so no rearrangement can work.

Example 3
first="tool", second="loot" → True
Constraints
  • 1 ≤ len(first), len(second) ≤ 5·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 problemsThe Sneaked-In Letter EasyDrop Adjacent Anagrams EasyTallest-First Roll Call EasyAnagram Buckets MediumEqual Letters Kept Apart Hard
loading Python…
Input
first="listen", second="silent"
Expected
True

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