Given two strings s and t, return true if and only if t is an anagram of s — that is, both strings contain exactly the same characters with the same frequencies.
Use a character-count hash map: walk s incrementing counts, then walk t decrementing. The strings are anagrams iff every count ends at zero (and the lengths match).
1 ≤ s.length, t.length ≤ 5 * 10⁴s and t consist of lowercase English letters.Different lengths → not an anagram. Bail out early.
Two strings are anagrams when they're made of the same letters the same number of times. The order is the only thing allowed to differ. So the job is to compare the two strings while ignoring order.
Time O(n)Space O(1)
The full walkthrough and code are part of Premium
true