Pattern
Arrays & Hashing
Reach for a hash table when a problem asks whether you have seen something before, or how often. You trade a little memory for a lookup that takes one step instead of a scan. Most of these run in O(n) time with O(n) memory.
1. Contains Duplicatearray · hash set · duplicatesEasy2. Valid Anagramstring · hash map · countingEasy3. Two Sumarray · pairsEasy4. Group Anagramsstring · hash map · sortingMed.5. Top K Frequent Elementsarray · hash map · bucket sort · heapMed.6. Product of Array Except Selfarray · prefix product · suffix productMed.7. Valid Sudokumatrix · hash set · simulationMed.8. Encode and Decode Stringsstring · design · encodingMed.9. Longest Consecutive Sequencearray · hash set · union findMed.