Complement pattern
Store what you have seen. For each x, check if target−x exists. This turns nested loops into one pass.
Lesson
Average O(1) lookup to trade space for time.
Loading solution…
Store what you have seen. For each x, check if target−x exists. This turns nested loops into one pass.
Anagrams, majority element, and isomorphic strings are frequency problems in disguise.
Showing 24 of the related problems in the 1000-question bank.
Two Sum
Hash Map
Longest Substring Without Repeating Characters
Sliding Window
Integer to Roman
Greedy
Roman to Integer
Greedy
Letter Combinations of a Phone Number
Backtracking
Substring with Concatenation of All Words
Sliding Window
Valid Sudoku
Hash Table
Sudoku Solver
Backtracking
First Missing Positive
Array
Group Anagrams
Hash Table
Set Matrix Zeroes
Matrix
Minimum Window Substring
Sliding Window
Word Ladder
BFS
Longest Consecutive Sequence
Hash Set
Copy List with Random Pointer
Linked List
Word Break
DP
Linked List Cycle
Two Pointers
Linked List Cycle II
Two Pointers
LRU Cache
Design
Intersection of Two Linked Lists
Two Pointers
Majority Element
Boyer-Moore
Implement Trie (Prefix Tree)
Trie
Contains Duplicate
Hash Set
Valid Anagram
Hash Table
Got the lesson?
Mark Hash Map & Set as understood when the ideas stick.