A Hash Map (dictionary in Python) is perhaps the MOST important data structure in coding interviews. It gives O(1) average lookup! 🗂️
💡 Think of it like this: Imagine a library where every book has a unique code. Instead of searching every shelf, you type the code into a computer and it tells you the EXACT location instantly. That's a hash map — it maps keys to values in constant time!
Hash Map operations (all O(1) average):
d[key] or d.get(key, default)d[key] = valuedel d[key]key in dThe #1 pattern: "Have I seen this before?" — Store things as you go and check for them in O(1):
If you see a problem asking about counting, grouping, finding duplicates, or pairing — think hash map first!
Run your code
yellow