Hash Map Crash Course For Coding Interviews

Hash = Chopping something up into small pieces.
Map = Taking those pieces and scrambling them into a number.

Kind of like hashing meat into ground beef.

It is probably most useful data structure for coding interviews.

It maps keys to values, allowing us O(1) access, insertion, and deletion.

Here are the topics you must know for coding interviews.

1) Hash Map Operations

→ Add/Remove Key-Value Pair
→ Check for Key
→ Check for Value
→ Access / Modify Value With Key
→ Iterate over keys, values, or key-value pairs

hashmap1
hashmap2
hashmap3
hashmap4

2) Common Use Cases for Hash Maps

→ Pair Sum Problems
→ Duplicate Detection
→ Counting

hashmap5
hashmap6
hashmap7

3) How Hash Maps Work Under the Hood

→ Insertion & Hashing
→ Hash Functions
→ Resizing & Rehashing
→ Open Addressing
→ Chaining

hashmap8
hashmap9
hashmap10
hashmap11

NOTES

  • The goal of this guide is to help you get up to speed with understanding hash maps and start solving problems

  • Technically, the O(1) refers to the average case for a hash map. In the worst case, the performance can degrade to O(n)

  • The hash function is critical to the hash map performing well

  • From a practical perspective, there are disadvantages to the hash map for smaller input sizes

  • Hash maps are unordered data structures that store key-value pairs. You should avoid using them when the order must be preserved