A hash map (Python dict) maps keys to values with instant lookups. Counting how often each item appears is one of its most common uses; the collections.Counter class does exactly this in one call.
Two strings are anagrams if one can be rearranged into the other, using every letter exactly once. Given two strings s and t, return True if t is an anagram of s and False otherwise.
Examples
Input: s = "anagram", t = "nagaram"
Output: True
Input: s = "rat", t = "car"
Output: False
Constraints
0 <= len(s), len(t) <= 5 * 10**4sandtconsist of lowercase English letters
Goals
- Count occurrences with a dictionary or collections.Counter
- Compare two collections by their contents rather than their order