Solutions with code and explanations to leetcode problems I have worked on
Number | Category | Problem name | Code | Whiteboard |
---|---|---|---|---|
1 | Dictionary/Misc | Two sum | python | explanation |
2 | Linked List, Recursion | Add two numbers | python | explanation |
3 | Sliding Window | Longest substring without repeating characters | python | explanation |
5 | DP | Longest palindroming substring | python | explanation |
14 | String | Longest common prefix | python | explanation |
16 | Sort, Two Pointers | 3 sum closest | python | explanation |
17 | Recursion | Letter combinations of phone numbers | python | explanation |
18 | Strings | 4Sum | python | explanation |
19 | Linked List | Remove Nth node from end of list | python | explanation |
21 | Linked List | Merge two sorted lists | python | explanation |
22 | Recursion/Backtracking | Generate parantheses | python | explanation |
27 | Two Pointers | Remove element | python | explanation |
33 | Binary Search | Search in rotated sorted array | python | explanation |
34 | Binary Search | Find first last position in sorted array | python | explanation |
38 | String | Count and say | python | explanation |
41 | Array | First missing positive | python | explanation |
56 | Sorting, Queue | Merge intervals | python | explanation |
60 | Misc | Permutation sequence | python | explanation |
71 | Stack | Simplify path | python | explanation |
75 | Sorting | Sort colours | python | explanation |
78 | Recursion/Backtracking | Subsets | python | explanation |
79 | Recursion/Backtracking | Word search | python | explanation |
88 | Merge Sort | Merge Sorted Array | python | explanation |
92 | Linked List | Reverse linked list II | python | explanation |
102 | BFS | Binary tree level order traversal | python | explanation |
120 | DP | Triangle | python | explanation |
128 | Dictionary | Longest consecutive sequence | python | explanation |
129 | Backtracking/DFS | Sum root to leaf numbers | python | explanation |
138 | Linked List | Copy list with random pointer | python | explanation |
139 | DP/Memoize | Word break | python | explanation |
141 | Linked List | Linked list cycle | python | explanation |
153 | Binary Search | Find minimum in rotated sorted array | python | explanation |
162 | Binary Search | Find peak element | python | explanation |
167 | Two Pointers | Two sum II | python | explanation |
198 | DP | House robber | python | explanation |
199 | BFS | Binary tree right side view | python | explanation |
206 | Linked List | Reverse linked list | python | explanation |
211 | Trie, Recursion | Design add and search words data structure | python | explanation |
213 | DP | House robber II | python | explanation |
215 | Sorting, Recursion | Kth largest element in an array | python | explanation |
216 | Backtracking | Combination sum III | python | explanation |
219 | Sliding Window | Contains duplicate II | python | explanation |
227 | Stack, Queue | Basic calculator II | python | explanation |
231 | Bit Manipulation | Power of two | python | explanation |
236 | Binary Tree, BFS/DFS | Lowest common ancestor of a binary tree | python | explanation |
249 | Dictionary | Group shifted strings | python | explanation |
270 | Recursion | Closest Binary Search Tree Value | python | explanation |
296 | Array | Best meeting point | python | explanation |
301 | Backtracking, DFS | Remove invalid parantheses | python | explanation |
311 | Array | Sparse matrix multiplication | python | explanation |
314 | BFS/DFS | Binary tree vertical order traversal | python | explanation |
322 | DP/Memoize | Coin Change | python | explanation |
323 | DFS/Union Find | Number of connected components in an undirected graph | python | explanation |
339 | Recursion | Nested list weight sum | python | explanation |
346 | Queue | Moving average from data stream | python | explanation |
347 | Recursion, Quick select/Heap | Top k frequent elements | TODO | explanation |
351 | Backtracking | Android unlock patterns | python | explanation |
352 | BST, Dictionary | Data stream as disjoint intervals | python | explanation |
356 | Dictionary | Line Reflection | python | explanation |
362 | Queue | Design hit counter | python | explanation |
380 | List, Dictionary | Insert delete get random O(1) | python | explanation |
399 | BFS | Evaluate division | python | explanation |
406 | Sorting | Queue reconstruction by height | python | explanation |
408 | String | Valid word abbreviation | python | explanation |
415 | Array, String | Add strings | python | explanation |
426 | Recursion/Tree traversal | Convert binary search tree to sorted doubly linked list | python | explanation |
443 | Two Pointer/Queue | String compression | python | explanation |
452 | Sorting, Greedy | Minimum number of arrows to burst balloons | python | explanation |
465 | Array | Optimal Account Balancing | python | explanation |
516 | DP/Memoize | Longest palindromic subsequence | python | explanation |
518 | DP/Memoize | Coin change 2 | python | explanation |
523 | Dictionary, Array, Precompute prefix | Continuous subarray sum | python | explanation |
528 | Binary Search | Random pick with weight | python | explanation |
632 | Heap, Sliding Window | Smallest range covering rlements from K lists | python | explanation |
636 | Stack | Exclusive time of functions | python | explanation |
642 | Trie | Design search autocomplete system | python | explanation |
670 | Sorting, Array | Maximum swap | python | explanation |
680 | Recursion | Valid Palindrome II | python | explanation |
691 | Recursion/Backtracking | Stickers to spell word | python | explanation |
708 | Linked List | Insert into a sorted circular linked list | python | explanation |
719 | Binary Search, Sliding Window | Find k-th smallest pair distance | python | explanation |
721 | Connected Components | Accounts Merge | python | explanation |
751 | Binary strings | IP to CIDE | python | explanation |
766 | Array | Toeplitz matrix | python | explanation |
791 | Dictionary | Custom sort string | python | explanation |
799 | DP | Champagne Tower | python | explanation |
809 | Two Pointers | Expressive words | TODO | explanation |
827 | Connected Components, DFS | Expressive words | python | explanation |
856 | Stack | Score of parantheses | python | explanation |
871 | Greedy, Heap/DP | Minimum number of refuelling stops | python | explanation |
921 | Stack | Minimum add to make parantheses valid | python | explanation |
938 | Recursion | Range sum of BST | python | explanation |
973 | Heap | K closest points to origin | python | explanation |
978 | Sliding Window | Longest turbulent subarray | python | TODO |
980 | Backtracking | Unique paths III | python | explanation |
981 | Binary Search, Dictionary | Time based key value store | python | explanation |
1047 | Stack | Remove all adjacent duplicates | python | explanation |
1091 | BFS | Shortest path in binary matrix | TODO | explanation |
1162 | BFS | As far from land as possible | python | TODO |
1249 | Stack | Minimum remove to make valid parentheses | python | explanation |
1293 | BFS | Shortest path in a grid with obstacles elimination | python | explanation |
1306 | BFS/DFS | Jump Game III | python | explanation |
1331 | Sorting, Array/Dictionary | Rank transform of an array | python | explanation |
1512 | Dictionary | Number of good pairs | python | Explanation |
1535 | Array | Find the winner of an array game | python | Explanation |
1650 | Binary Tree | Lowest common ancestor of a binary tree III | python | Explanation |
1762 | Array | Buildings with an ocean view | python | explanation |
1926 | BFS | Nearest exit from entrance in maze | python | explanation |
2002 | Enumerative/DP | Max product of length of two palindromic subsequences | python | explanation |
2095 | Linked List | Delete the middle node of a linked list | python | explanation |
2115 | Recursion/Topological Sort | Find all possible recipes from given supplies | python | explanation |
2232 | String | Minimize result by adding parantheses to expression | python | explanation |
2251 | Queue, Heap | Number of flowers in full bloom | python | explanation |
2265 | Recursion/Tree Traversal | Count nodes equal to average of subtree | python | explanation |
2302 | Sliding Window | Count subarrays with score less than k | python | explanation |
2433 | Bit Manipulation | Find the original array of prefix XOR | python | explanation |
2483 | Array | Minimum penalty for a shop | python | explanation |
2815 | Array | Max pair sum in array | python | explanation |
2817 | Minimum absolute difference between elements with constraint | TODO | explanation | |
2843 | Array | Count symmetric integers | python | explanation |
2845 | Misc | Count of interesting sub arrays | python | explanation |
2859 | Bit Manipulation | Sum of values at indices with K set bits | python | explanation |
2860 | Queue, Stack, Sorting | Happy students | python | explanation |
2861 | Linear Programming/Binary Search | Maximum number of alloys | python | explanation |
3002 | Math, Sets | Maximum size of a set after removals | python | explanation |