Hash Map / Set

Use for counts, de-dupe, lookups, two-sum, anagrams, prefix sums.

What this pattern is

Use hash-based O(1)-average lookups for frequency counting, membership tests, and complement searches. Ideal for de-duplication and pair problems.

Exercise: groupAnagrams

Task: Group a list of strings into lists of anagrams.
Example: ["eat","tea","tan","ate","nat","bat"] → [["eat","tea","ate"],["tan","nat"],["bat"]]
Edge cases: mixed case, empty strings, very long strings.

Your Solution

Exercise: twoSum

Task: Given an unsorted array nums and target t, return indices [i, j] such that nums[i] + nums[j] = t (or [-1,-1]). Use a map of value→index while scanning.
Example: nums=[2,7,11,15], t=9 → [0,1]
Edge cases: duplicates, negative/zero values, no solution.

Your Solution