Problem · String
Check Anagrams Without Sorting
Learn this problemProblem statement
Given two lowercase English strings first and second, return whether they are anagrams.
Two strings are anagrams when every letter has the same frequency in both strings. Solve the task with character-frequency counting; do not sort either string.
Function
areAnagrams(first: String, second: String) → booleanExamples
Example 1
first = "listen"second = "silent"return = trueBoth words contain the same six letters with equal frequencies.
Example 2
first = "aab"second = "abb"return = falseThe multiplicities of a and b differ.
Example 3
first = "amazon"second = "amazon"return = trueA string is an anagram of itself.
Constraints
1 <= first.length, second.length <= 100000.- Both strings contain only lowercase English letters.
- Do not sort the strings.