Loading section...
dict vs Counter: Always Reach for Counter First
Concepts: pyCounter, pyFrequencyMap
Every interview that involves frequency counting starts with a choice: build the map manually with a plain dict, or use collections.Counter. Most candidates reach for a dict because it feels more 'raw' and impressive. This is exactly backwards. Reaching for Counter is the power move. Counter is a subclass of dict that was designed specifically for counting. It has more functionality, cleaner syntax, and zero performance penalty. Using dict when Counter exists is like using a spoon to drive a screw: it works, but it tells the interviewer you do not know your tools. Counter's Four Power Features The most_common(k) method is the one you will use constantly. It returns the top-k elements sorted by count, descending. Under the hood it uses heapq.nlargest, which is O(n log k) — faster than sorti