Most Common Leetcode DSA Patterns
Most Common Leetcode DSA Patterns
Most Common Leetcode DSA Patterns
DSA Patterns
Solve Maximum problems!
Swipe >>
If input array is sorted then :
Binary Search, Two Pointers.
If asked for all
permutations/subsets then :
Backtracking.
If given a Tree/Graph then :
DFS & BFS.
If given a linked list then :
Two Pointers.
Swipe >>
If recursion is banned then :
Stack, Queue.
If must solve in-place then :
- Swap corresponding values
- Store one or more different values
in the same pointer.
If asked for maximum/minimum
subarray/subset/options then :
Dynamic programming
.
Swipe >>
If asked for top/least K items :
Heap.
If asked for common strings then :
Map, Trie.
Others :
- Map/Set for O(1) time & O(n) space.
- Sort input for O(nlogn) time and
O(1) space.
Swipe >>
Thanks
We missed something?