The most common use of hash maps is to turn O(n) lookups into O(1). Whenever you find yourself using nested loops to "find" something, consider if a hash map could eliminate the inner loop.
The Pattern
Common Applications
Two Sum Variations
Finding Complements
Index Lookups
Checking Existence in Reference
Precomputation Pattern
Build a lookup table once, then query it many times.
Graph Representation
When to Use This Pattern
You have a nested loop where the inner loop searches for something
You're doing repeated lookups in a collection
You need to find pairs/complements that satisfy a condition
You're matching elements between two collections
The problem involves "finding if X exists"
Trade-offs
Time: O(n²) ā O(n)
Space: O(1) ā O(n)
This is almost always a worthwhile trade-off in interviews, where time complexity is usually more important than space.