Hash Maps mind map

Key–value lookups, counting, and frequency maps.

Core idea: Trade memory for an O(1) question: what must I know about what I have already seen?

Mnemonic: Key → ask → remember · Cost: O(n) space · O(1) average lookup

Count: Frequency & signature

Signal: Identity depends on occurrences rather than position.

Move: Map each key to a count; sort or serialize counts when equivalent groups need one key.

Examples: Ransom Note, Top K Frequent, Group Anagrams

Match: Complement lookup

Signal: A future value can complete the answer with something already seen.

Move: Ask for the complement before storing the current value and its useful metadata.

Examples: Two Sum, Pair Difference, Isomorphic Strings

Remember: Identity & latest position

Signal: Objects must be cloned, deduplicated, or tracked across time.

Move: Store original → copy, or value → most useful index, then wire or bound from the map.

Examples: Copy Random List, Longest Unique Substring, LRU Cache

Balance: Prefix lookup

Signal: A subarray is defined by a target sum or equalized counts.

Move: Look for the earlier prefix that makes the current prefix complete the target.

Examples: Subarray Sum Equals K, Contiguous Array, Divisible Subarrays

Every mind map