Same Letters, Other Order

EasyHash Map≈ 15 min

Two phrases are written with the same letters when one can be turned into the other by reordering its letters. Upper and lower case do not matter, and spaces are ignored. Given the phrases first and second, return true if they use the same letters, each the same number of times, and false if not.

The phrases hold only the letters a–z and A–Z, and spaces. A phrase counts as using the same letters as itself.

Examples

text
first = "Dormitory", second = "dirty room"     →  true
first = "listen", second = "silent"            →  true
first = "apple", second = "paper"              →  false
first = "Astronomer", second = "Moon starer"   →  true

In the third example both phrases have five letters and two ps, but "apple" has an l where "paper" has an r.

Constraints

  • Each phrase holds between 0 and 50,000 characters.
  • Aim for O(n) in the length of both phrases together. Sorting both, at O(n log n), passes too.
Sound off. Turn on for key clicks and a chime when the tests pass.Inline suggestions off. Recommended while you are learning. Turn on to complete words as you type.
Console
›Run to see what your code prints

Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.