I believe that practising algorithms every day is a long-term investment in my life.
- golang, python, js
- Binary Search
- Binary Search Tree
- Binary Tree
- N-aray Tree(Trie)
- Graph(Dijkstra, Union Find, Kruskal, Prim's, Minimum Spanning Tree, Topological Ordering...etc)
- Stack
- Queue
- Array
- Sorting
- Hash Table
- Heap
- Linked list
- Bit Operation
- Dynamic programming(Kadan's)
- Backtracking(Permutations & Combinations & Subsets...etc)
- Math
- and more...
- leetcode
- project euler
- glassdoor
- interviews
- ...
| Day | Task | Type | From | remarks |
|---|---|---|---|---|
| 1 | binary search | binary search | leetcode 704 | π |
| 2 | sqrt(x) | binary search | leetcode 69 | |
| 3 | search in rotated sorted array | binary search | leetcode 33 | π |
| 4 | Find Peak Element | binary search | leetcode 162 | |
| 5 | Find Minimum in Rotated Sorted Array | binary search | leetcode 153 | π |
| 6 | Find Minimum in Rotated Sorted Array | binary search | leetcode 153 | π2 extra solutions for day5 |
| 7 | Search for a Range | binary search | leetcode 34 | |
| 8 | Find K Closest Elements | binary search | leetcode 658 | |
| 9 | Closest Binary Search Tree Value | binary search, tree | leetcode 270 | 1st attemp 10sep2018, 2nd 20jan2019 |
| 10 | Closest Binary Search Tree Value | binary search, tree | leetcode 270 | revise day9 problems with legit recursive & iterative dfs |
| 11 | Breadth First Search | tree | basics: revise breadth first search | |
| 12 | Search in a Sorted Array of Unknown Size | binary search | leetcode 702 | golang unsupported on leetcode, do it in python instead |
| 13 | Pow(x, n) | binary search | leetcode 50 | i failed to come up with the solution myself, the solution is mind blowing |
| 14 | Valid Perfect Square | binary search | leetcode 50 | |
| 15 | Find Smallest Letter Greater Than Target | binary search | leetcode 50 | |
| 16 | Lower & Upper Bound Binary Searches | binary search | my medium article | |
| 17 | Intersection of Two Arrays | binary search, hashtable | leetcode 349 | |
| 18 | Intersection of Two Arrays II | binary search, hashtable | leetcode 350 | |
| 19 | Two Sum II | binary search, hashtable | leetcode 167 | |
| 20 | Find the Duplicate Number | binary search, hashtable | leetcode 287 | |
| 21 | Find Minimum in Rotated Sorted Array II | binary search | leetcode 154 | π very hard classic question |
| 22 | Validate Binary Search Tree | binary tree | leetcode 98 | π 1st 25sep2018 2nd 18mar2019 |
| 23 | Inorder Successor in BST | binary tree | leetcode 285 | my O(logn) solution is unique βπ», tho the suggested solution is jaw-dropping and much more terse |
| 24 | Depth First Search | binary tree | ||
| 25 | Binary Search Tree Iterator | BST | leetcode 173 | my first solution was super slow tho it passes the OJ. The suggested solution is awesome |
| 26 | Search in a Binary Search Tree | binary tree | leetcode 700 | |
| 27 | Iterative inorder traversal on BST | binary tree | π | |
| 28 | Pre & post order traversal on BST | binary tree | π | |
| 29 | Insert into a Binary Search Tree | BST | leetcode 701 | recursive & iterative |
| 30 | Delete a node in a BST | BST | leetcode 450 | my 1st attempt was super discursive LOL |
| 31 | Delete a node in a BST | BST | leetcode 450 | π classic approach, bottom up recursion to replace the target node with its successor |
| 32 | Pre & In & Post Order Depth First Search | tree | revision on tree traversals | |
| 33 | Kth Largest Element in a Stream | BST | leetcode 703 | my first attempt "Time Limit Exceeded" |
| 34 | Kth Largest Element in a Stream | BST | leetcode 703 | learned what is heap and did a heap solution |
| 35 | Lowest Common Ancestor of a Binary Search Tree | BST | leetcode 235 | β |
| 36 | Convert Sorted Array to Binary Search Tree | BST | leetcode 108 | |
| 37 | Balanced Binary Tree | Tree | leetcode 110 | |
| 38 | Contains Duplicate III | array, BST, bucket | leetcode 220 | π§ I don't understand the suggested solutions in BST and Bucket |
| 39 | Lowest Common Ancestor of a Binary Tree | tree | leetcode 226 | β even O(2n) leads to Time Limit Exceeded, what a draconian challenge. checkout suggestion |
| 40 | Recursive Binary Search | binary tree | to understand the logic of recursion | |
| 41 | Binary Tree Preorder Traversal | binary tree | ||
| 42 | N-ary Tree Preorder Traversal | N-ary tree | leetcode 589 | |
| 43 | Binary Tree Inorder Traversal | binary tree | leetcode 94 | the iterative solution is mind blowing |
| 44 | Binary Tree Postorder Traversal | binary tree | leetcode 145 | |
| 45 | Binary Tree Postorder Traversal | binary tree | leetcode 145 | to understand the trick of the iterative solution |
| 46 | N-ary Tree Postorder Traversal | N-ary tree | leetcode 590 | |
| 47 | Binary Tree Level Order Traversal | binary tree | leetcode 102 | |
| 48 | N-ary Tree Level Order Traversal | N-ary tree | leetcode 429 | |
| 49 | Maximum Depth of Binary Tree | binary tree | leetcode 104 | |
| 50 | Maximum Depth of N-ary Tree | N-ary tree | leetcode 559 | |
| 51 | Symmetric Tree | binary tree | leetcode 101 | |
| 52 | Path Sum | binary tree | leetcode 112 | iterative, recursive |
| 53 | Populating Next Right Pointers in Each Node I & II | binary tree | leetcode 116 | actaully my initial solution is O(n) in complexity and use only O(1) in space, it is good enough to apply on II as well |
| 54 | Construct String from Binary Tree | binary tree | leetcode 606 | |
| 55 | Binary Tree Right Side View | binary tree | leetcode 199 | 2nd & 3rd attempt beat 100% |
| 56 | Construct Binary Tree from Inorder and Postorder Traversal | binary tree | leetcode 106 | |
| 57 | Construct Binary Tree from Preorder and Inorder Traversal | binary tree | leetcode 105 | |
| 58 | Construct Binary Tree from Preorder and Postorder Traversal | binary tree | leetcode 889 | similar to day 56,57 |
| 59 | Serialize and Deserilize Binary Tree | |||
| tree | leetcode 889 | serialize | ||
| 60 | Serialize and Deserilize Binary Tree | binary tree | leetcode 297 | deserialize βπ» this is a HARD question, i made it finally. this concept is very important π |
| 61 | Serialize and Deserilize BST | binary tree | leetcode 449 | π actually the concept of day60 is applicable here in BST |
| 62 | Serialize and Deserilize N-ary Tree | binary tree | leetcode 428 | My naive approach was to use json, it actaully beats 42.29%...not bad π The suggested approach is astonishing π³ |
| 63 | Encode N-ary Tree to Binary Tree | binary tree | leetcode 431 | encode β decode π€ |
| 64 | Encode N-ary Tree to Binary Tree | binary tree | leetcode 431 | encode β decode β This question is pretty hard, it spent me 2 nights but it was worth doing. |
| 65 | Implement Trie (Prefix Tree) | trie | leetcode 208 | insert |
| 66 | Implement Trie (Prefix Tree) | trie | leetcode 208 | search, startwith |
| 67 | Map Sum Pairs | trie | leetcode 677 | i like this |
| 68 | Replace Words | string | leetcode 648 | my 1st hasty solution got passed, but i think it is incorrect so i made another one |
| 69 | Add and Search Word Data Structure | string | leetcode 211 | AddWord |
| 70 | Add and Search Word Data Structure | string | leetcode 211 | Search |
| 71 | Implement Trie (Prefix Tree) | trie | leetcode 208 | another approach: array instead of hashtable and it is faster |
| 72 | Design Search Autocomplete System | trie | leetcode 642 | constructor and insert |
| 73 | Design Search Autocomplete System | trie | leetcode 642 | search(incomplete) |
| 73 | Design Search Autocomplete System | trie | leetcode 642 | WTF with leetcode |
| 74 | Implement Trie (Prefix Tree) | trie | leetcode 208 | just do it again with python cos im gonna try autocomplete with python |
| 75 | Design Search Autocomplete System | trie | leetcode 642 | do the same thing in python and i got accepted, fuck leetcode |
| 76 | Design Search Autocomplete System | trie | leetcode 642 | i finally made it in golang and I BEAT 100% submissions |
| 77 | Word Search | trie | leetcode 79 | my 1st attempt got TLE, it is weird cos the notion is correct |
| 78 | Word Search II | trie | leetcode 212 | its actually a follow-up of day77 problem, tho my snippet can only beats 14% π |
| 79 | Moving Average from Data Stream | queue | leetcode 346 | 2 solutions |
| 80 | Design Circular Queue | queue | leetcode 622 | front, rear, isEmpty, isFull, enqueue, dequeue |
| 81 | Walls and Gates | queue/tree | leetcode 286 | it is actually a lot easier to implement using dfs than using queue |
| 82 | Number of Islands | queue/tree | leetcode 200 | 1st attempt:dfs beats 9.4%, 2nd attempt:dfs beats 100%, 3rd attempt:bfs beats 50.43% |
| 83 | Open the Lock | queue/tree | leetcode 752 | very interesting question, 1st attempt beats 5%, 2nd attempt beats 85% |
| 84 | Perfect Squares | queue/tree | leetcode 279 | bfs: 204ms beats 36% |
| 85 | Count Primes | dynamic programming | leetcode 204 | 1st attempt TLE, 2nd attempt: learned from the others, 3rd: optimization |
| 86 | Min Stack | stack | leetcode 155 | βοΈ |
| 87 | Valid Parentheses | stack | leetcode 20 | |
| 88 | Daily Temperatures | stack | leetcode 739 | kinda dynamic programming approach |
| 89 | Evaluate Reverse Polish Notation | stack | leetcode 739 | very direct, beats 100% |
| 90 | Clone Graph | graph | leetcode 133 | βοΈ 1st graph question: iterative bfs for now, will try different approaches |
| 91 | Clone Graph | graph, stack, queue | leetcode 133 | βοΈ 2nd attempt: iterative dfs, 3rd attempt: recursive dfs |
| 92 | Target Sum | graph, stack | leetcode 494 | 1st attempt: iterative dfs beats 57%. 2nd attempt: recursive dfs beats 27% |
| 93 | Implement Queue using Stacks | queue, stack | leetcode 232 | π classic question. my classic solution also beats 100% |
| 94 | Implement Stack using Queues | queue, stack | leetcode 225 | π classic question. my classic solution also beats 100% |
| 95 | Decode String | stack | leetcode 394 | π€‘ interesting question, beats 100% using a stack |
| 96 | Flood Fill | recursion, queue | leetcode 733 | actually the question is quite similar to the one on day82. recursion beats 92%, bfs beats 11% |
| 97 | Design HashSet | hashtable | leetcode 705 | very good question. 1st navie approach beats 6.9%, 2nd another naive beats 51% |
| 98 | Design HashMap | hashtable | leetcode 706 | very good question. 1st navie approach beats 3.28% |
| 99 | Contains Duplicate | hashtable | leetcode 217 | |
| 100 | Single Number | hashtable, math, beat operation | leetcode 136 | βπ»π€ day 100 with a π classic question, 1st, 2nd beats 51%, 3rd beats 100% |
| 101 | Happy Number | hashtable | leetcode 202 | very interesting question |
| 102 | Ugly Number | math, recursion | leetcode 263 | 1st beats 5%, 2nd beats 5%, optimal beats 100% |
| 103 | Two Sum | hashtable | leetcode 1 | O(n) beats 100%, O(2n) beats 55%, O(n^2) beats 14% |
| 104 | Find the Unique Mistyped Item In an Unsorted Array | hashtable | βοΈ Basic but not easy. I was asked by a friend who works at a top startup | |
| 105 | Isomorphic Strings | hashtable | leetcode 205 | 1st beats 1%, 2nd beats 5.88% |
| 106 | Minimum Index Sum of Two Lists | hashtable | leetcode 599 | 1st beats 93.33% |
| 107 | Largest product in a grid | array | euler 11 | |
| 108 | First Unique Character in a String | hashtable | leetcode 387 | 1st beats 10.32%, 2nd beats 100% |
| 109 | Contains Duplicate II | hashtable | leetcode 219 | 1st beats 87.34% |
| 109 | Amicable numbers | array | euler 21 | 2nd question today |
| 110 | Logger Rate Limiter | hashtable | leetcode 359 | i think there is only one common solution |
| 110 | Group Anagrams | hashtable | leetcode 49 | 1st beats 96.55%, 2nd beats 89.66% |
| 111 | Coin Change | hashtable, dynamic programming | leetcode 322 | βοΈ 2 years ago, I gave up. today i nailed it πͺπ» 1st beats 13.75%, 2nd beats 25.32%, 3rd beats 96.2% |
| 112 | Combination Sum IV | hashtable, tree, dynamic programming | leetcode 377 | βοΈ classic DP, classic solution |
| 112 | Coin Sums | hashtable, tree, dynamic programming, backtracking | euler 31 | βοΈ this question is similar to the previous one but the tricky thing is it requires DIFFERENT combinations |
| 113 | Coin Change II | hashtable, tree, dynamic programming, backtracking | leetcode 518 | βοΈ this question is exactly the same with the two on day112 but leetcode is draconian in the Time Limit |
| 114 | Design Linked List | linked list | leetcode 707 | π classic implementation of linked list operation |
| 115 | Intersection of Two Linked Lists | linked list | leetcode 160 | π tricky linked list question, 3 approaches but only one is considered as Linked List related |
| 115 | Reverse Linked List | linked list | leetcode 206 | π 2nd approach is more linked list related |
| 115 | FizzBuzz | array | leetcode 206 | 1st beats 82.49%, 2nd beats 95.48% |
| 115 | Multiples of 3 and 5 | array | euler 1 | did it in a row becos it is similar to day115 q3 FizzBuzz |
| 116 | Linked List Cycle | linked list | leetcode 141 | π classic question |
| 116 | Linked List Cycle II | linked list | leetcode 142 | π classic question |
| 117 | Remove Nth Node From End of List | linked list | leetcode 19 | π classic question, 1 classic + 2 other approaches |
| 117 | Remove Linked List Elements | linked list | leetcode 19 | π classic question |
| 118 | Odd Even Linked List | linked list | leetcode 118 | both naive and classic approach still beats 100% LOL |
| 118 | Palindrome Linked List | linked list | leetcode 234 | naive beats 100% LOL |
| 118 | Valid Sudoku | hashtable | leetcode 36 | very straight forward O(3n) solution beats 31.25%. But the 2 one-pass solutions also beats 31.25% π€ |
| 118 | Permutations | backtracking, recursion | π basic | |
| 118 | Permutations | backtracking, recursion | leetcode 46 | π recursive beats 77.21%, iterative beats 77.14% |
| 119 | Permutations II | backtracking, recursion | leetcode 47 | π 1st attempt 7.41% |
| 120 | Permutations II | backtracking, recursion | leetcode 47 | 2nd day on the same question for understanding π 2nd attempt use hashtable which beats 100%(46.47% for python) |
| 121 | Median of Two Sorted Arrays | array | leetcode 4 | 1st O(nlogn), 2nd O(m+n) already beats 100%, suggested solution is hard to understand |
| 121 | Find the K th Element in 2 Sorted Arrays | array | asked by a friend | 1st O(nlogn), 2nd O(m+n), suggested solution is hard to understand(see main.py) |
| 122 | Next Permutation | backtracking, recursion | leetcode 31 | 1st O(n) beats 100%, 2nd O(n) is terse and it beats 100% |
| 122 | Combinations | backtracking, recursion | leetcode 77 | π 1st beats 1.22%, 2nd beats 9.76%, 3rd beats 12.20% |
| 123 | Subsets | backtracking, recursion | leetcode 78 | π both 1st, 2nd & 3rd beat 100 but python vers beat 35.29%, 3.67% and 35.29% only π€ |
| 123 | Subsets II | backtracking, recursion | leetcode 90 | π 1st beats 100% but python ver beat 41.22% only π€ |
| 124 | Subsets II | backtracking, recursion | leetcode 90 | π spent more time to understand the iterative approach, although it eventaully beats merely 29.41% |
| 125 | Letter Combinations of a Phone Number | recursion | interview | asked by the facebook interviewer |
| 126 | Recursion | recursion | π a little intro of recursion of Standford CS106B | |
| 127 | Combination Sum | hashtable, dynamic programming, backtracking | leetcode 39 | π similar to day113, Coin Change II. 1st beats 23.85%, 2nd beats 63.08% |
| 127 | Combination Sum II | recursion, backtracking | leetcode 40 | very similer to day119, Permutations II. 1st beats 38.89%, 2nd beats 100%. π Be careful of the nuance between it and Combination Sum |
| 127 | Combination Sum III | recursion, backtracking | leetcode 216 | π very similer to day112, Combination Sum IV and day124, Subsets II. 1st beats 100% |
| 128 | Fibonacci | recursion, dynamic programming | leetcode 509 | π classic DP. top-down recursion beats 100%. bottom-up iteration beats 100% |
| 128 | Climbing Staris | recursion, dynamic programming | leetcode 70 | π classic DP. top-down recursion beats 100%. bottom-up iteration beats 100% |
| 128 | Min Cost Climbing Staris | dynamic programming | leetcode 746 | π classic DP. bruce forece recursion TLE. bottom-up iteration beats 100% |
| 128 | First Missing Positive | array | leetcode 41 | 1 in go beats 100%, 2 in python |
| 129 | Meeting Rooms | sort, greedy | leetcode 252 | βοΈinterval, 1st beats 100% πtakeaway: sort.Slice() |
| 129 | Meeting Rooms II | sort, greedy | leetcode 253 | βοΈinterval, 1st beats 0%, 2nd beats 96.97% |
| 130 | Reverse Integer | array | leetcode 7 | π 1st & 2nd approach 4ms. i gave up 2 years ago, now i finally know how to do it |
| 130 | Merge Sorted Array | sort, array | leetcode 88 | π 1st naive approach 0ms. 2nd is learned from others |
| 131 | Longest Common Substring | array, dynamic programming | π 1st is naive. 2nd approach is classic | |
| 131 | Search a 2D Matrix | binary search | leetcode 74 | revise binary search, both 1st and 2nd is 8ms |
| 131 | Search a 2D Matrix II | binary search | leetcode 240 | revise binary search, 1st and 2nd are 32ms beats 100% |
| 132 | Longest Common Subsequence | array, dynamic programming | π 1st dynamic programming. 2nd recursive, 3rd recursive memorization | |
| 132 | Range Sum Query - Immutable | array, dynamic programming | 1st brute force beats 46%, 2nd cache beats 100% | |
| 132 | Range Sum Query 2D - Immutable | array, dynamic programming | 1st beats 80% | |
| 133 | Bubble Sort | sort | revise sorting | |
| 133 | Selection Sort | sort | revise sorting | |
| 133 | Insertion Sort | sort | revise sorting | |
| 133 | Merge Sort | sort | revise sorting | |
| 133 | Quick Sort | sort | revise sorting. spaced & in-place | |
| 134 | Rectangle Overlap | math | leetode 836 | i hate this kind of questions |
| 134 | Rectangle Area | math | leetode 223 | i hate this kind of questions |
| 134 | Minimum Absolute Difference in BST | BST | leetode 530 | |
| 134 | Find Bottom Left Tree Value | tree | leetode 513 | both bfs & dfs run 12ms and beat 100% |
| 134 | Path Sum III | tree | leetode 437 | 1st LTE. 2nd 24ms beats 28.57% |
| 135 | Find Pivot Index | array, math | leetode 724 | i failed to come up with a correct approach, learned from others |
| 135 | Largest Number At Least Twice of Others | array, sort | leetode 747 | 1st O(nlogn), 2nd O(n) |
| 135 | Plus One | array | leetode 66 | should be just one solution |
| 135 | Find the Invalid Node in a BST | array | glassdoor | |
| 135 | Minimum Distance Between BST Nodes | BST | leetode 783 | this question is exactly the same wih leetcode 530 |
| 135 | Unique Email Addresses | string | leetode 929 | |
| 135 | Continuous Subarray Sum | array | leetode 523 | 1st 104ms beats 0% LOL, 2nd 92ms beats 33.33% |
| 135 | String to Integer (atoi) | array | leetode 8 | 1st & 2nd 4ms beats 100%, fuck the corner cases |
| 136 | Diagonal Traverse | array | leetode 498 | 1st beats 22.22% |
| 136 | Spiral Matrix | array | leetode 54 | 1st, 2nd beats 100% βοΈ 3rd is stunning |
| 136 | Pascals Triangle | array | leetode 118 | 1st beats 100% |
| 136 | Pascals Triangle II | array | leetode 119 | 1st, 2nd beats 100% |
| 136 | Minimum Path Sum | array, dynamic programming | leetode 64 | 1st 220ms beats 0%, π 2nd beats 100% |
| 137 | Jewels and Stones | hashtable | leetode 771 | 1st hashtable 0ms beats 100% |
| 137 | Number of 1 Bits | bit op | leetode 191 | π the key here is to practice bit operation, i ignore any attempts using strings |
| 137 | Reverse Bits | bit op | leetode 190 | π the key here is to practice bit operation, i ignore any attempts using strings |
| 138 | LRU Cache | hashtable, linked list | leetode 146 | πππ |
| 138 | Correct Flights Route | array | interview | π€ interesting...1st O(n^2), 2nd O(n) |
| 138 | Length of Last Word | array | leetcode 58 | not a good question |
| 139 | Count and Say | array | leetcode 38 | βοΈ |
| 139 | LFU Cache | hashtable, linked list | leetode 460 | πππ 1st attempt learned from others, 2nd attempt is my own and new way to implement it(although it is not efficient) |
| 140 | Count Complete Tree Nodes | binary tree | leetode 222 | 1st 24ms beats 92%, 2nd 20ms beats 100% |
| 141 | Container With Most Water | array | leetode 11 | 1st 368ms beats 34%, 2nd 12ms beats 100% |
| 141 | Add Binary | array, string | leetode 67 | 1st 0ms beats 100% |
| 141 | Implement strStr() | array, string | leetode 28 | 1st 544ms beats 2.04%, 2nd 0ms beats 100% |
| 141 | Longest Common Prefix | array, string | leetode 14 | 1st 4ms beats 12.90%, 2nd 0ms beats 100% |
| 141 | Remove Duplicates from Sorted Array | array, string | leetode 14 | 1st 220ms beats 2.04%(.py 19% .js 47%), 2nd 60ms beats 100% |
| 141 | Remove Duplicates from Sorted Array II | array, string | leetode 80 | 1st, 2nd 8ms beats 100% |
| 142 | Spiral Matrix II | array, string | leetode 59 | 1st 0ms beats 100% |
| 142 | Merge Two Binary Trees | tree | leetode 617 | 1st 40ms beats 59.15%, 2nd 36ms beats 100% |
| 143 | Reverse String | string | leetode 344 | |
| 143 | Array Partition I | array | leetode 561 | 1st beats 5.48%, 2nd 128ms beats 12.33% |
| 143 | Remove Element | array | leetode 27 | 1st beats 100%. i also implement it in JS with 2 ways |
| 143 | Minimum Size Subarray Sum | array | leetode 209 | οΈβοΈ 1st beats 5.8%, 2nd beats 20%, 3rd learned from others |
| 143 | Maximum Product of Three Numbers | array | leetode 628 | βοΈ 1st beats 28.57%, 2nd 44ms beats 100% |
| 143 | Reverse Only Letters | array | leetode 917 | |
| 143 | Flipping an Image | array | leetode 832 | |
| 144 | Most Common Word | string | leetode 819 | takeaway: python=>re.split(r'\W+', paragraph). go=>regexp.MustCompile([!?',;. ]). js=>paragraph.split(/[!?',;. ]/) |
| 144 | Subtree of Another Tree | tree | leetode 572 | 1st 24ms beats 100% |
| 144 | Subtree with Maximum Average | tree | 1point3acres | |
| 144 | Divide Two Integers | math | leetcode 29 | π classic question in hk interviews |
| 144 | Product of Array Except Self | math | leetcode 238 | using / got beting 60%. naive got TLE, proper approach 2836ms beats 5.92% |
| 145 | K Closest Points to Origin | sort, heap | leetcode 973 | π 1st beats 72.46%. 2nd beats 98.95% in python |
| 145 | Gray Code | array, bit op | leetcode 89 | π€ interesting |
| 145 | Longest Substring with At Most Two Distinct Characters | array, hashtable | leetcode 159 | 1st, 2nd beat 17.65% |
| 145 | Maximize Distance to Closest Person | array | leetcode 849 | 1st beats 100% |
| 146 | Max Stack | stack | leetcode 716 | very similar to Day 86: Min Stack |
| 146 | Middle of the Linked List | linked list | leetcode 876 | π |
| 146 | Insert into a Cyclic Sorted List | linked list | leetcode 708 | π |
| 146 | Merge Two Sorted Lists | linked list | leetcode 21 | π |
| 146 | Merge k Sorted Lists | linked list | leetcode 23 | π naive approach runs faster than the decent approach π |
| 146 | Remove Duplicates from Sorted List II | linked list | leetcode 82 | π 1st, 2nd beats 100% |
| 147 | Network Delay Time | graph | leetcode 743 | π Dijkstra's Algorithm. Altenative: DFS |
| 147 | Cheapest Flights Within K Stops | graph | leetcode 787 | BTS: TLE. need to use π Dijkstra's variation |
| 148 | Longest Palindromic Substring | string | leetcode 5 | βοΈ |
| 148 | Maximum Size Subarray Sum Equals k | array | leetcode 325 | 1st appraoach LTE, 2nd approach learned from others which beats 100% |
| 148 | Subarray Sum Equals K | array | leetcode 560 | 1st appraoach refers to leetcode 325, therefore i came up with the idea immediately which beats 100% |
| 149 | Maze | array | glassdoor | οΈβοΈ |
| 149 | 2 Sum Closest | array | glassdoor | βοΈ |
| 149 | Reverse 2nd Half of a Linked List | linked list | glassdoor | π |
| 149 | Reverse Linked List II | linked list | leetcode 92 | οΈπ |
| 149 | Window Sum | array | glassdoor | βοΈ |
| 149 | To Lower Case | array | leetcode 709 | οΈ |
| 149 | Sort Array By Parity | array | leetcode 905 | οΈ |
| 149 | Sort Array By Parity II | array | leetcode 922 | οΈ |
| 149 | Robot Return to Origin | string | leetcode 657 | οΈ1st beats 100%, 2nd beats 0% π |
| 149 | Find Anagram Mappings | array | leetcode 760 | οΈ |
| 149 | Uncommon Words from Two Sentences | hashtable | leetcode 884 | οΈ |
| 149 | Rotate String | string | leetcode 796 | οΈ |
| 150 | Find Leaves of Binary Tree | tree | leetcode 336 | οΈ1st O(h*n) beats 100% |
| 150 | Second Minimum Node In a Binary Tree | tree | leetcode 671 | οΈ1st, 2nd O(n) beats 100% |
| 150 | Two Sum IV - Input is a BST | tree | leetcode 653 | οΈ1st, 2nd O(n) beats 50% only π€ |
| 150 | Increasing Order Search Tree | tree | leetcode 897 | οΈ1st O(n) beats 100% |
| 150 | Reverse Words in a String II | array | leetcode 186 | οΈ1st O(n) beats 100% |
| 150 | Compare Version Numbers | array | leetcode 165 | οΈ1st O(n) beats 100% |
| 150 | Sum Root to Leaf Numbers | tree | leetcode 129 | οΈ1st, 2nd O(n) beats 100% |
| 150 | Number of Connected Components in an Undirected Graph | hashtable, graph | leetcode 323 | οΈ1st beats 100% |
| 150 | Maximum Binary Tree | tree | leetcode 654 | οΈ1st beats 0%. 2nd beats 100% |
| 151 | Rotate Function | tree | leetcode 396 | οΈ1st O(n^2) beats 100%, 2nd O(n) beats 100% |
| 151 | Rotate List | linked list | leetcode 61 | οΈ1st O(n) beats 100% |
| 151 | Arithmetic Slices | array | leetcode 413 | οΈ1st O(n) beats 100% |
| 152 | Round Robin | queue | glassdoor | οΈπππ |
| 152 | Sliding Window Median | array | leetcode 480 | βοΈ 1st O(n*nlogn) 100% |
| 152 | Permutation in String | hashtable, array, string | leetcode 480 | βοΈ 1st O(n^2) hashtable beats 0%, 2nd O(n^2) [26]int{} beats 40% |
| 152 | Set Matrix Zeroes | hashtable, array | leetcode 73 | 1st O(n) beats 52% |
| 152 | Top K Frequent Elements | hashtable, bucket sort | leetcode 347 | 1st O(nlogn) beats 64%. 2nd O(n) beats 64%. takeaway: use bucket sort for frequency questions, 3rd ~O(n) quick select |
| 153 | Top K Frequent Words | hashtable, bucket sort | leetcode 692 | 1st O(2nlogn) beats 25%. 2nd O(nlogn) beats 100%. takeaway: sort things with priority queue using priority WITH other params |
| 153 | Sort Characters By Frequency | hashtable, bucket sort | leetcode 451 | 1st O(n) beats 66% |
| 153 | Zigzag Iterator | array | leetcode 281 | 1st O(k) beats 61%. leetcode doesn't support golang, did it in python |
| 153 | Triangle | dfs, dynamic programming | leetcode 120 | π 1st TLE, 2nd MLE. 3rd dp in O(n) beats 100% |
| 154 | Products' Average Rating | array | glassdoor | βοΈ |
| 154 | Greatest Common Divisor | math | glassdoor | βοΈ takeaway: Euclidian Algorithm |
| 154 | Least Common Multiple | math | glassdoor | βοΈ takeaway: A * B = LCM * GCD |
| 154 | Cells Mutation | array | glassdoor | βοΈ |
| 154 | Amplitude of a Tree | tree | glassdoor | βοΈ |
| 155 | Union Find | graph, union find | Study Union Find | π Quick Find ππ» -> Quick Union π€ -> Union Find π |
| 155 | Minimum Spanning Tree | graph, union find | Study MST | π heap + list of hashtables π€ -> Kruskal(Union Find) π or Prim(heap + hashtable) |
| 156 | Go Through all the Warehouses with Minimum Cost | graph, union find | glassdoor | π real life problem <- Kruskal, Prim |
| 156 | Minimum Window Substring | 2pointers, hashtable | leetcode 76 | 1st O(n) beats 20% |
| 157 | LRU Cache Miss Count | linked list, hashtable | glassdoor | 1st O(n^2), 2nd O(n) |
| 157 | Four Integers | array | glassdoor | O(nlogn) |
| 157 | Rotate a Matrix | array | glassdoor | 1st space O(n), π i2nd space O(1) in-place |
| 157 | Rotate Image | array | leetcode 48 | π inplace |
| 157 | Copy List with Random Pointer | linked list | leetcode 138 | βοΈ |
| 158 | Path Sum IV | linked list | leetcode 138 | 1st O(4n) |
| 158 | Binary Tree Vertical Order Traversal | tree | leetcode 314 | 1st recursive, 2nd iterative, both O(n) |
| 158 | Course Schedule | graph | leetcode 207 | 1st LTE, π 2nd Classic Approach: Topological Ordering |
| 159 | Topological Ordering | graph | study | π 1st: Topological Ordering with DFS π 2nd: Topological Ordering with BFS/Khan's |
| 159 | Course Schedule II | graph | leetcode 210 | π DFS, BFS |
| 160 | Order Dependency | graph | glassdoor | π DFS, BFS |
| 160 | Graph Valid Tree | graph, union find | leetcode 261 | π 1st union find O(nlogn) beats 100% |
| 160 | Merge Strings | array | glassdoor | βοΈ very similar to ZigZag iterator |
| 160 | Find Distinct Substrings with Exactly K Distinct Characters | array | π1st O(n^3), 2nd O(n^2) | |
| 161 | Reorder Log Files | array | leetcode 937 | 1st O(nlogn) |
| 161 | Dijkstra's Algorithm on a Directed Graph | graph | study | π |
| 161 | Dijkstra's Algorithm on an Undirected Graph | graph | study | π |
| 161 | Find All Anagrams in a String | string | leetcode 438 | 1st, 2nd O(kn) |
| 162 | Optimal Flights | binary search | interview | π1st O(n^2), 2nd O(nlogn) |
| 162 | Max Area of Island | array | leetcode 695 | 1st O(n) |
| 162 | Find K Pairs with Smallest Sums | array | leetcode 373 | 1st 2nd O(nlogn) |
| 163 | Number of Distinct Islands | array | leetcode 694 | 1st O(nk) |
| 163 | Kth Largest Element in an Array | array, heap | leetcode 215 | 1st, 2nd O(nlogn) |
| 163 | Number of Islands II | array | leetcode 305 | 1st O(n^2) beats 6% LOL |
| 163 | Redundant Connection | union find | leetcode 684 | O(nlogn) |
| 164 | Friends Circles | union find | leetcode 547 | O(nlogn) |
| 164 | Sentence Similarity II | union find | leetcode 737 | O(nlogn) |
| 165 | Sentence Similarity | hashtable | leetcode 734 | βO(n) |
| 166 | Heap | heap | study | π implement a heap with push, pop and heapify |
| 166 | Heap Sort | heap, sort | study | π implement heapsort using a heap |
| 166 | Generate Parentheses | backtracking | study | π1st O(2^2n) beats 5% |
| 166 | Count Univalue Subtrees | tree | leetcode 250 | π1st O(n) 100% |
| 167 | Decode Ways | dynamic programing | leetcode 91 | βοΈ1st brute force TLE, 2nd memorized brute force O(n) beats 100% |
| 167 | Unique Paths | dynamic programing | leetcode 62 | πclassic DP, bottom up recursion with memorization, O(mn) beats 100% |
| 167 | Merge Intervals | sort, greedy | leetcode 56 | βοΈinterval |
| 168 | Non-overlapping Intervals | sort, greedy | leetcode 435 | βοΈinterval |
| 168 | Minimum Number of Arrows to Burst Balloons | sort, greedy | leetcode 452 | βοΈinterval |
| 168 | Largest BST Subtree | BST | leetcode 333 | 1st O(n^2) |
| 168 | Range Sum of BST | BST | leetcode 938 | 1st recursive, 2nd iterative, both O(n) beat 98% |
| 169 | Delete a node in a BST | BST | leetcode 450 | π[revise day30] 2 classic approaches, bottom up recursion to replace the target node with its predecessor or successor |
| 169 | Inorder Successor in BST | BST | leetcode 285 | π [revise day23] iterative and recursive O(logn) |
| 169 | Inorder Successor in BST II | BST | leetcode 510 | βοΈ interesting, would be a potential follow-up of leetcode 285 |
| 169 | Closest Binary Search Tree Value II | BST | leetcode 272 | β 1st O(nlogn) |
| 170 | Split BST | BST | leetcode 776 | πππ super hard recursion question, must revise again |
| 170 | Unique Word Abbreviation | hashtable | leetcode 288 | |
| 170 | Longest Substring Without Repeating Characters | hashtable | leetcode 3 | π 1st O(n^2), 2nd O(n) |
| 170 | Repeated DNA Sequences | hashtable | leetcode 187 | 1st O(n) |
| 170 | Find Duplicate Subtrees | hashtable, tree | leetcode 652 | 1st O(n) |
| 170 | Group Shifted Strings | hashtable | leetcode 249 | O(n) |
| 171 | K-th Symbol in Grammar | hashtable | leetcode 779 | 1st LTE. π2nd tricky recursion. see ./idea.jpeg |
| 171 | 3Sum | hashtable, 2pointers | leetcode 779 | π1st hashtable O(n^2) beats 18%. π2nd hashtable+2pointers O(n^2) beats 27%, π3rd hashtable+2pointers O(n^2) beats 54% |
| 171 | Two Sum III - Data structure design | hashtable | leetcode 170 | π1st hashtable O(n) beats 100% |
| 171 | 4Sum | hashtable | leetcode 18 | π1st hashtable O(n^3) beats 15%, 2nd hashtable+2pointer O(n^3) beats 95% |
| 171 | 4Sum II | hashtable | leetcode 454 | π1st O(n^3), 2nd O(n^2) |
| 172 | Insert Delete GetRandom O(1) | hashtable | leetcode 380 | 1st random O(n) beats 6%, π2nd random O(1) beats 100% |
| 172 | Insert Delete GetRandom O(1) - Duplicates allowed | hashtable | leetcode 381 | 1st random O(n) beats 6% |
| 173 | Find Median from Data Stream | heap, bst | leetcode 295 | 1st heap, 2nd BST both LTE, π3rd: 2 heaps |
| 173 | Lonely Pixel I | hashtable | leetcode 531 | 1st, 2nd beats 100% |
| 173 | Minimum Add/Delete to Make Parentheses Valid | stack | leetcode 921 | 1st O(n) beats 100% |
| 173 | Largest Permutation | permutation | geeksforgeeks | |
| 174 | Integer to English Words | array | leetcode 273 | βοΈtedious but frequently asked |
| 174 | Remove duplicates from a string in O(1) space | hashtable, bucket | geeksforgeeks | β 1st O(n) space, 2nd O(1) space |
| 175 | Design Hit Counter | hashtable, array | leetcode 362 | β 1st python OrderedDict O(1) for all operations beats 100%, 2nd hashtable+array beats 100% |
| 175 | Design Tic-Tac-Toe | array | leetcode 348 | 1st O(n^2), π±2nd O(1) |
| 175 | Valid Tic-Tac-Toe State | array | leetcode 794 | my thought is so stupid |
| 176 | Repeated Substring Pattern | array | leetcode 459 | 1st O(n^2), 2nd O(n) |
| 176 | Repeated String Match | array | leetcode 686 | 1st O(kn) |
| 176 | License Key Formatting | array, stack | leetcode 482 | 1st O(n) |
| 176 | Serialize and Deserialize array of string | array | geeksforgeeks | O(n) |
| 177 | Letter Case Permutation | permutation | leetcode 784 | 1st permutation+hashset O(2^n), 2nd permutation O(2^n) |
| 177 | Best Time to Buy and Sell Stock | dynamic programming | leetcode 121 | πππ1st dp O(n), 2nd heap O(nlogn) |
| 177 | Best Time to Buy and Sell Stock II | dynamic programming | leetcode 122 | πππ1st, 2nd dp O(n) |
| 178 | Best Time to Buy and Sell Stock III | dynamic programming | leetcode 122 | πππ1st O(n^2) LTE, 2nd O(2n) beats 32% |
| 178 | Minimum Time Difference | sort | leetcode 539 | 1st O(nlogn) beats 73%, 2nd O(n) beats 93% |
| 178 | Next Closest Time | string | leetcode 681 | βοΈ so many corner cases, it was the worst attempt i ever made |
| 179 | Game of Life | array, bit op | leetcode 289 | 1st space O(mn), 2nd space O(1) |
| 179 | Add Two Numbers | linked list | leetcode 2 | π1st, 2nd O(n) |
| 179 | Add Two Numbers II | linked list | leetcode 445 | π1st O(n) |
| 179 | Topological Ordering Of IDs | graph | revise | implement topological ordering of a list of IDs |
| 179 | Alien Dictionary | array, graph | leetcode 269 | π1st BFS, 2nd DFS |
| 180 | Letter Combinations of a Phone Number | recursion | leetcode 17 | π |
| 180 | Multiply Strings | array | leetcode 43 | π |
| 180 | Add Strings | array | leetcode 415 | π |
| 181 | Valid Word Square | array | leetcode 422 | |
| 181 | Maximum Subarray | array | leetcode 53 | 1st O(n^2) πππ2nd, 3rd O(n) Kadan's Algorithm. This problem can be applied to Minimum Subarray |
| 181 | Maximum Product Subarray | array | leetcode 152 | 1st O(n^2) πππ2nd O(n) Kadan's Algorithm. This problem can be applied to Minimum Product Subarray |
| 181 | Subarray Product Less Than K | array | leetcode 713 | βοΈsliding window |
| 182 | Word Ladder | bfs, hashtable | leetcode 127 | 1st LTE, βοΈ2nd O(n^26*l) |
| 182 | Word Ladder II | bfs, hashtable | leetcode 127 | LTE, revise later |
| 182 | Minimum Genetic Mutation | bfs, hashtable | leetcode 433 | 1st O(MN) |
| 183 | Bold Words in String | hashtable, sort | leetcode 433 | οΈοΈβοΈ1st O(nlogn): interval problem |
| 183 | Add Bold Tag in String | hashtable, sort | leetcode 616 | βοΈ1st O(nlogn): interval problem |
| 183 | Number of Segments in a String | string | leetcode 616 | takeawaystrings.Fields(s) |
| 183 | Sort Colors | bucket | leetcode 75 | 0th merge sort O(nlogn), 1st bucket sort O(2n), π2nd moving zeros swap O(2n), π3rd partitioning swap O(n) |
| 183 | Move Zeroes | array | leetcode 75 | βοΈswap |
| 183 | Missing Number | bucket, math | leetcode 268 | 1st math O(n), 2nd bucket O(2n) |
| 184 | Swap Nodes in Pairs | linked list | leetcode 24 | π |
| 184 | Reverse Nodes in k-Group | linked list | leetcode 25 | π |
| 184 | Sort List | linked list, sort | leetcode 148 | πmerge sort |
| 184 | Peeking Iterator | design | leetcode 284 | leetcode doesnt support golang |
| 184 | One Edit Distance | array | leetcode 161 | 1st O(3n), 2nd O(n) |
| 184 | Zero/K Sum Subarray(s) | array | glassdoor | πsimilar to leetcode 325 and leetcode 560 |
| 185 | Edit Distance | dynamic programming | leetcode 72 | πππ similar to LCS |
| 185 | Shortest Unsorted Continuous Subarray | sort, array | leetcode 581 | 1st O(nlogn), 2nd O(n) |
| 185 | Maximum Average Subarray | dynamic programming | glassdoor | π1st O(nlogn), 2nd O(n) |
| 185 | Maximum Average Subarray I | array | leetcode 643 | sliding window O(n) |
| 185 | Subdomain Visit Count | string | leetcode 811 | 1st O(n) |
| 185 | Trapping Rain Water | dynamic programming | leetcode 42 | 1st O(3n) |
| 186 | Unique Binary Search Trees | dynamic programming | leetcode 96 | βοΈCatalan Number Sequence very similar to the Fibonacci Sequence |
| 187 | Valid Palindrome | 2pointers | leetcode 125 | π |
| 187 | Valid Palindrome II | 2pointers | leetcode 680 | π1st O(n), 2nd O(n) too but more readable |
| 188 | Cut Off Trees for Golf Event | heap, sort | leetcode 675 | π1st heap, 2nd sort |
| 188 | Lowest Common Ancestor of a N-ary Tree | tree | glassdoor | βοΈ |
| 188 | Distance Between 2 Values in a BST | tree | glassdoor | βοΈbuild BST => find LCA => ans = depth(a) + depth(b) - 2*depth(lca) |
| 189 | Reverse Words in a String | string | leetcode 151 | 1st time=space=O(n) |
| 189 | Max Consecutive Ones | array | leetcode 485 | O(n) |
| 189 | Max Consecutive Ones II | array | leetcode 487 | O(2n) |
| 189 | Max Consecutive Ones III | array | leetcode 1004 | 1st O(n^2), 2nd O(2n) |
| 189 | Pacific Atlantic Water Flow | graph | leetcode 417 | 1st O(n^2) |
| 190 | Design Compressed String Iterator | string, queue | leetcode 604 | 1st O(n) unicode.IsDigit() |
| 190 | Basic Calculator II | string, stack | leetcode 227 | 1st O(2n), takeaway: isdigit() in python, unicode.IsDigit() in golang, and isinstance(a, int) in python for type checking, π2nd O(2n) too but more concise but be careful of float division |
| 191 | Array Partition by Occurence | hashtable | interview | βοΈ O(n^2) |
| 192 | Partition Labels | hashtable | leetcode 763 | οΈοΈοΈβοΈWTF, I was asked about it yestarday during an interview. 1st O(n^2). 2nd O(n) |
| 192 | Basic Calculator | string, stack | leetcode 224 | 1st O(2n) tedious operation beats 25%, 2nd concise O(2n) beats 90% |
| 193 | Basic Calculator III | string, stack, recursion | leetcode 772 | 1st O(n^2) recursion, 2nd O(n) recursion |
| 193 | Sort Transformed Array | 2pointers | leetcode 360 | 1st O(n) |
| 194 | Quick Select | sort | revision | revise Quick Sort and use it to find the k-th smallest element in O(n) time |
| 195 | 01 Matrix | bfs, dynamic programming | leetcode 542 | 1st BFS O(n^2) LTE, 2nd DP O(2n) beats 96% |
| 195 | Recover Binary Search Tree | tree | leetcode 99 | 1st inroder+sort O(nlogn), 2nd inorder O(n) |
| 195 | Baseball Game | stack | leetcode 682 | 1st O(n) |
| 195 | Sort a Stack using a Stack | stack | Sort Stacks | βοΈ |
| 196 | N-Queens | backtracking | leetcode 51 | π1st classic backtracking approach |
| 196 | N-Queens II | backtracking | leetcode 52 | π1st classic backtracking approach |
| 196 | Search in Rotated Sorted Array II | binary search | leetcode 81 | πclassic binary search question similar to leetcode 33 |
| 196 | Kth Smallest Element in a Sorted Matrix | heap, binary search | leetcode 378 | βοΈ 1st O(nlogn) sort, βοΈ2nd O(nlogn) max heap, 3rd O(logn*logn) binary search |
| 197 | Maximal Square | dynamic programming | leetcode 221 | πdynamic programming in linear time O(n) |
| 197 | Binary Search Variations | binary search | revision | πcommon, lower & upper bound in both iterative and recursive implementation |
| 197 | Factorial Trailing Zeroes | math | leetcode 172 | β |
| 198 | Quick Select | sort | revision | wrote the quick select again in both go & python for better understanding |