Same Letters, Other Order
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
first = "Dormitory", second = "dirty room" → true
first = "listen", second = "silent" → true
first = "apple", second = "paper" → false
first = "Astronomer", second = "Moon starer" → trueIn 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.
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.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.