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.
In a word game you lay out letter tiles spelling s, then try to slide those very tiles around until they spell t: no tile may be added, left over or used twice. Return True when that works (t is then an anagram of s) and False when it does not.
Examples
Input: s = "stressed", t = "desserts"
Output: True
Input: s = "cart", t = "tram"
Output: False
Explanation: same length, but "tram" needs an m and has no use for the c.
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