This problem follows the Frequency Count pattern, commonly found in the Arrays & Hashing category. Recognizing this pattern is key to solving it efficiently in an interview setting.
Count character frequencies with a hash map. Compare both strings.
Using a fixed-size array of 26 keeps space O(1) — you don't need a hash map for lowercase English letters.
if len(s) != len(t): return false
count = [0] * 26
for i in range(len(s)):
count[ord(s[i]) - ord('a')] += 1
count[ord(t[i]) - ord('a')] -= 1
return all(c == 0 for c in count)Practice Valid Anagram and similar Arrays & Hashing problems with flashcards. Build pattern recognition through active recall.
Practice this problem