LeetCode Β· HashMap

HashMap Problem Set

Complement lookup, canonical grouping, prefix-sum maps, and key→node design patterns. If the brute-force solution keeps rescanning for matches, a HashMap usually removes the inner loop.

Related pages: HashMap Β· Arrays & Hashing
DifficultyPatternProblemKey Insight
Easyhash-mapLC 1 Β· Two SumStore previously seen values by number, then check whether target - nums[i] has already appeared.
MediumgroupingLC 49 Β· Group AnagramsCanonicalize each word, then use that canonical form as the map key to collect anagram groups.
MediumfrequencyLC 347 Β· Top K Frequent ElementsHashMap builds counts in one pass; a heap or bucket structure then extracts the top-k answers efficiently.
Mediumprefix-sumLC 560 Β· Subarray Sum Equals KStore how many times each prefix sum has appeared. If currentSum - k exists, every occurrence contributes one valid subarray ending here.
Mediumset+map-adjacentLC 128 Β· Longest Consecutive SequenceUsually solved with a HashSet, but it belongs in the broader hashing toolkit: O(1) membership checks let you expand only from sequence starts.
MediumdesignLC 146 Β· LRU CacheHashMap gives O(1) lookup by key, while a doubly linked list gives O(1) eviction and move-to-front. You need both structures together.
Practice note: Solution write-ups already exist for LC 1, 49, 347, and 128. LC 560 and LC 146 are intentionally listed here as canonical HashMap practice problems even though their dedicated solution pages have not been added yet.

← Back to Arrays & Hashing problems