Last active
October 9, 2022 12:15
-
-
Save avin/5dfa4230c4b5291b71c85f74600c8344 to your computer and use it in GitHub Desktop.
solve-algorithm-guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original text from: https://seanprashad.com/leetcode-patterns/ | |
---- | |
If input array is sorted then | |
- Binary search | |
- Two pointers | |
If asked for all permutations/subsets then | |
- Backtracking | |
If given a tree then | |
- DFS | |
- BFS | |
If given a graph then | |
- DFS | |
- BFS | |
If given a linked list then | |
- Two pointers | |
If recursion is banned then | |
- Stack | |
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 | |
If asked for top/least K items then | |
- Heap | |
- QuickSelect | |
If asked for common strings then | |
- Map | |
- Trie | |
Else | |
- Map/Set for O(1) time & O(n) space | |
- Sort input for O(nlogn) time and O(1) space |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment