If you often find yourself grappling with how to tackle LeetCode problems, our repo is here to assist you!
LeetCode Pattern 500 is meticulously designed to facilitate your swift adaptation to diverse problem types and their numerous variations by discerning recurring patterns within these problems.
What is LeetCode Pattern 500
LeetCode Pattern 500 is inspired by Blind 75 and Grind 75's classic problem selection. LeetCode Pattern 500 offers 500 solutions for LeetCode problems in Python and Java, 17 notes on essential concepts related to data structures and algorithms, and 130 patterns for solving LeetCode problems. Most importantly, each solution provides analysis of which pattern to be used and the time/space complexity. This comprehensive resource can help you improve your coding skills, deepen your understanding of fundamental DSA topics, and prepare for SDE interviews.
Mind map for all 130 patterns in LeetCode Pattern 500
Check our mind map in Figma.
Suggestions & Questions
Feel free to raise issues or post in discussions.
Num | Grind 75 | Name | Topic | Pattern | Solution |
---|---|---|---|---|---|
001 | tree note |
[A]tree | |||
002 | O | 100. Same Tree | [A]tree-divide-and-conquer | two branch top-down | Python Java |
003 | O | 101. Symmetric Tree | [A]tree-divide-and-conquer | two branch top-down | Python Java |
004 | O | 98. Validate Binary Search Tree | [A]tree-divide-and-conquer | two branch top-down | Python Java |
005 | O | 105. Construct Binary Tree from Preorder and Inorder Traversal | [A]tree-divide-and-conquer | re-build tree (top-down) | Python Java |
006 | 106. Construct Binary Tree from Inorder and Postorder Traversal | [A]tree-divide-and-conquer | re-build tree (top-down) | Python Java | |
007 | 889. Construct Binary Tree from Preorder and Postorder Traversal | [A]tree-divide-and-conquer | re-build tree (top-down) | Python | |
008 | 1008. Construct Binary Search Tree from Preorder Traversal | [A]tree-divide-and-conquer | re-build BST (top-down approach) | Python | |
009 | O | 108. Convert Sorted Array to Binary Search Tree | [A]tree-divide-and-conquer | re-build BST (top-down approach) | Python Java |
010 | 109. Convert Sorted List to Binary Search Tree | [A]tree-divide-and-conquer | re-build BST (inorder approach) | Python | |
011 | 700. Search in a Binary Search Tree | [A]tree-divide-and-conquer | use BST attributes | Python | |
012 | 701. Insert into a Binary Search Tree | [A]tree-divide-and-conquer | use BST attributes | Python | |
013 | O | 285. Inorder Successor in BST | [A]tree-divide-and-conquer | use BST attributes | Python |
014 | 450. Delete Node in a BST | [A]tree-divide-and-conquer | use BST attributes | Python | |
015 | O | 235. Lowest Common Ancestor of a Binary Search Tree | [A]tree-divide-and-conquer | find LCA | Python Java |
016 | 1650. Lowest Common Ancestor of a Binary Tree III | [A]tree-divide-and-conquer | find LCA | Python | |
017 | 116. Populating Next Right Pointers in Each Node | [A]tree-divide-and-conquer | populate next ptr | Python | |
018 | 117. Populating Next Right Pointers in Each Node II | [A]tree-divide-and-conquer | populate next ptr | Python | |
019 | 96. Unique Binary Search Trees | [A]tree-divide-and-conquer | unique BST | Python | |
020 | 95. Unique Binary Search Trees II | [A]tree-divide-and-conquer | unique BST | Python | |
021 | 872. Leaf-Similar Trees | [A]tree-dfs-preorder | preorder | Python | |
022 | O | 226. Invert Binary Tree | [A]tree-dfs-preorder | preorder | Python Java |
023 | 1448. Count Good Nodes in Binary Tree | [A]tree-dfs-preorder | preorder | Python | |
024 | 1457. Pseudo-Palindromic Paths in a Binary Tree | [A]tree-dfs-preorder | preorder | Python | |
025 | O | 572. Subtree of Another Tree | [A]tree-dfs-preorder | turn tree to string | Python Java |
026 | 606. Construct String from Binary Tree | [A]tree-dfs-preorder | turn tree to string | Python | |
027 | O | 297. Serialize and Deserialize Binary Tree | [A]tree-dfs-preorder | turn tree to string | Python |
028 | 449. Serialize and Deserialize BST | [A]tree-dfs-preorder | turn tree to string | Python | |
029 | 545. Boundary of Binary Tree | [A]tree-dfs-preorder | record leaves | Python | |
030 | 94. Binary Tree Inorder Traversal | [A]tree-dfs-inorder | inorder | Python | |
031 | O | 230. Kth Smallest Element in a BST | [A]tree-dfs-inorder | inorder | Python Java |
032 | 173. Binary Search Tree Iterator | [A]tree-dfs-inorder | inorder | Python | |
033 | 99. Recover Binary Search Tree | [A]tree-dfs-inorder | inorder | Python | |
034 | 366. Find Leaves of Binary Tree | [A]tree-dfs-postorder | postorder | Python | |
035 | O | 236. Lowest Common Ancestor of a Binary Tree | [A]tree-dfs-postorder | postorder | Python Java |
036 | O | 124. Binary Tree Maximum Path Sum | [A]tree-dfs-postorder | postorder | Python |
037 | O | 543. Diameter of Binary Tree | [A]tree-dfs-postorder | postorder | Python Java |
038 | O | 110. Balanced Binary Tree | [A]tree-dfs-postorder | postorder | Python Java |
039 | 865. Smallest Subtree with all the Deepest Nodes | [A]tree-dfs-postorder | postorder | Python | |
040 | 1120. Maximum Average Subtree | [A]tree-dfs-postorder | postorder | Python | |
041 | 298. Binary Tree Longest Consecutive Sequence | [A]tree-dfs-postorder | postorder | Python | |
042 | 1644. Lowest Common Ancestor of a Binary Tree II | [A]tree-dfs-postorder | postorder | Python | |
043 | 1145. Binary Tree Coloring Game | [A]tree-dfs-postorder | postorder | Python | |
044 | 2246. Longest Path With Different Adjacent Characters | [A]tree-dfs-postorder | postorder | Python | |
045 | O | 102. Binary Tree Level Order Traversal | [A]tree-bfs | bfs | Python Java |
046 | O | 103. Binary Tree Zigzag Level Order Traversal | [A]tree-bfs | bfs | Python |
047 | O | 199. Binary Tree Right Side View | [A]tree-bfs | bfs | Python Java |
048 | O | 104. Maximum Depth of Binary Tree | [A]tree-bfs | bfs | Python Java |
049 | 2415. Reverse Odd Levels of Binary Tree | [A]tree-bfs | bfs | Python | |
050 | 623. Add One Row to Tree | [A]tree-bfs | bfs | Python | |
051 | 690. Employee Importance | [A]tree-bfs | bfs | Python | |
052 | O | 863. All Nodes Distance K in Binary Tree | [A]tree-bfs | build a child_parent hashmap | Python |
053 | 2385. Amount of Time for Binary Tree to Be Infected | [A]tree-bfs | build a child_parent hashmap | Python | |
054 | O | 662. Maximum Width of Binary Tree | [A]tree-bfs | assign idx | Python |
055 | 314. Binary Tree Vertical Order Traversal | [A]tree-bfs | assign coordinates | Python | |
056 | 987. Vertical Order Traversal of a Binary Tree | [A]tree-bfs | assign coordinates | Python | |
057 | linked-list note |
[B]linked-list | |||
058 | O | 21. Merge Two Sorted Lists | [B]linked-list | use sentinel node | Python Java |
059 | O | 328. Odd Even Linked List | [B]linked-list | use sentinel node | Python |
060 | O | 2. Add Two Numbers | [B]linked-list | use sentinel node | Python Java |
061 | O | 19. Remove Nth Node From End of List | [B]linked-list | use sentinel node | Python |
062 | 369. Plus One Linked List | [B]linked-list | use sentinel node | Python | |
063 | O | 141. Linked List Cycle | [B]linked-list | use two pointers (slow and fast) | Python Java |
064 | 142. Linked List Cycle II | [B]linked-list | use two pointers (slow and fast) | Python | |
065 | O | 876. Middle of the Linked List | [B]linked-list | use two pointers (slow and fast) | Python Java |
066 | O | 206. Reverse Linked List | [B]linked-list | use two pointers (prev and cur) | Python Java |
067 | 92. Reverse Linked List II | [B]linked-list | use two pointers (prev and cur) | Python | |
068 | O | 25. Reverse Nodes in k-Group | [B]linked-list | use two pointers (prev and cur) | Python |
069 | 2074. Reverse Nodes in Even Length Groups | [B]linked-list | use two pointers (prev and cur) | Python | |
070 | O | 24. Swap Nodes in Pairs | [B]linked-list | use two pointers (prev and cur) | Python |
071 | 1836. Remove Duplicates From an Unsorted Linked List | [B]linked-list | use two pointers (prev and cur) | Python | |
072 | 83. Remove Duplicates from Sorted List | [B]linked-list | use two pointers (prev and cur) | Python | |
073 | 82. Remove Duplicates from Sorted List II | [B]linked-list | use two pointers (prev and cur) | Python | |
074 | 160. Intersection of Two Linked Lists | [B]linked-list | use two pointers (find LCA/intersection) | Python | |
075 | O | 234. Palindrome Linked List | [B]linked-list | use two pointers (utilize symmetry property) | Python Java |
076 | O | 143. Reorder List | [B]linked-list | use two pointers (utilize symmetry property) | Python |
077 | 2130. Maximum Twin Sum of a Linked List | [B]linked-list | use two pointers (utilize symmetry property) | Python | |
078 | O | 61. Rotate List | [B]linked-list | get linked list length | Python |
079 | 1019. Next Greater Node In Linked List | [B]linked-list | get linked list length | Python | |
080 | O | 148. Sort List | [B]linked-list | use merge sort to sort list | Python |
081 | 138. Copy List with Random Pointer | [B]linked-list | interweaving nodes | Python | |
082 | O | 146. LRU Cache | [B]linked-list | use dll and hashmap together | Python Java |
083 | 460. LFU Cache | [B]linked-list | use dll and hashmap together | Python | |
084 | 432. All O`one Data Structure | [B]linked-list | use dll and hashmap together | Python | |
085 | 237. Delete Node in a Linked List | [B]linked-list | change val as change node | Python | |
086 | 1206. Design Skiplist | [B]linked-list | skiplist | Python | |
087 | hashmap note |
[C]hashmap | |||
088 | 705. Design HashSet | [C]hashmap | separate chaining | Python | |
089 | 706. Design HashMap | [C]hashmap | separate chaining | Python | |
090 | 1805. Number of Different Integers in a String | [C]hashmap | store val | Python | |
091 | O | 217. Contains Duplicate | [C]hashmap | store val | Python Java |
092 | O | 128. Longest Consecutive Sequence | [C]hashmap | store val | Python Java |
093 | O | 13. Roman to Integer | [C]hashmap | store val | Python Java |
094 | 953. Verifying an Alien Dictionary | [C]hashmap | store val | Python | |
095 | 2342. Max Sum of a Pair With Equal Sum of Digits | [C]hashmap | store val | Python | |
096 | O | 336. Palindrome Pairs | [C]hashmap | store val | Python |
097 | O | 1. Two Sum | [C]hashmap | store val | Python Java |
098 | O | 380. Insert Delete GetRandom O(1) | [C]hashmap | store val | Python |
099 | 381. Insert Delete GetRandom O(1) - Duplicates allowed | [C]hashmap | store val | Python | |
100 | 734. Sentence Similarity | [C]hashmap | store val | Python | |
101 | 609. Find Duplicate File in System | [C]hashmap | store val | Python | |
102 | 249. Group Shifted Strings | [C]hashmap | store val | Python | |
103 | O | 383. Ransom Note | [C]hashmap | store sth’s freq | Python Java |
104 | O | 242. Valid Anagram | [C]hashmap | store sth’s freq | Python Java |
105 | O | 409. Longest Palindrome | [C]hashmap | store sth’s freq | Python Java |
106 | 387. First Unique Character in a String | [C]hashmap | store sth’s freq | Python Java | |
107 | 767. Reorganize String | [C]hashmap | store sth’s freq | Python | |
108 | 266. Palindrome Permutation | [C]hashmap | store sth’s freq | Python | |
109 | 2423. Remove Letter To Equalize Frequency | [C]hashmap | store sth’s freq | Python | |
110 | 299. Bulls and Cows | [C]hashmap | store sth’s freq | Python | |
111 | 819. Most Common Word | [C]hashmap | store sth’s freq | Python | |
112 | O | 49. Group Anagrams | [C]hashmap | store sth’s freq | Python Java |
113 | 1152. Analyze User Website Visit Pattern | [C]hashmap | store sth’s freq | Python | |
114 | 828. Count Unique Characters of All Substrings of a Given String | [C]hashmap | snapshot of hashmap | Python | |
115 | 1055. Shortest Way to Form String | [C]hashmap | snapshot of hashmap | Python | |
116 | 205. Isomorphic Strings | [C]hashmap | build bijection mapping relation | Python Java | |
117 | 890. Find and Replace Pattern | [C]hashmap | build bijection mapping relation | Python | |
118 | 1010. Pairs of Songs With Total Durations Divisible by 60 | [C]hashmap | store valid val’s freq for finding pairs | Python | |
119 | 2364. Count Number of Bad Pairs | [C]hashmap | store valid val’s freq for finding pairs | Python | |
120 | 2013. Detect Squares | [C]hashmap | store valid val’s freq for finding pairs | Python | |
121 | binary-search note |
[D]binary-search | |||
122 | O | 704. Binary Search | [D]binary-search | search in a sorted array for specific val | Python Java |
123 | 367. Valid Perfect Square | [D]binary-search | search in a sorted array for specific val | Python | |
124 | O | 74. Search a 2D Matrix | [D]binary-search | search in a sorted array for specific val | Python Java |
125 | 34. Find First and Last Position of Element in Sorted Array | [D]binary-search | search in a sorted array for specific val | Python Java | |
126 | 702. Search in a Sorted Array of Unknown Size | [D]binary-search | search in a sorted array for specific val | Python | |
127 | 35. Search Insert Position | [D]binary-search | search in a sorted array for most close val | Python Java | |
128 | 1428. Leftmost Column with at Least a One | [D]binary-search | search in a sorted array for most close val | Python | |
129 | 744. Find Smallest Letter Greater Than Target | [D]binary-search | search in a sorted array for most close val | Python | |
130 | O | 981. Time Based Key-Value Store | [D]binary-search | search in a sorted array for most close val | Python Java |
131 | O | 528. Random Pick with Weight | [D]binary-search | search in a sorted array for most close val | Python |
132 | O | 278. First Bad Version | [D]binary-search | search in sth’s range | Python Java |
133 | 222. Count Complete Tree Nodes | [D]binary-search | search in sth’s range | Python | |
134 | 878. Nth Magical Number | [D]binary-search | search in sth’s range | Python | |
135 | 1201. Ugly Number III | [D]binary-search | search in sth’s range | Python | |
136 | O | 4. Median of Two Sorted Arrays | [D]binary-search | search in sth’s range | Python |
137 | 1062. Longest Repeating Substring | [D]binary-search | search in sth’s range | Python | |
138 | 1011. Capacity To Ship Packages Within D Days | [D]binary-search | search in sth’s range | Python | |
139 | 875. Koko Eating Bananas | [D]binary-search | search in sth’s range | Python | |
140 | 719. Find K-th Smallest Pair Distance | [D]binary-search | search in sth’s range | Python | |
141 | 852. Peak Index in a Mountain Array | [D]binary-search | use boundary to record | Python | |
142 | O | 658. Find K Closest Elements | [D]binary-search | use boundary to record | Python |
143 | 162. Find Peak Element | [D]binary-search | use boundary to record | Python | |
144 | O | 33. Search in Rotated Sorted Array | [D]binary-search | rotated sorted array | Python Java |
145 | 81. Search in Rotated Sorted Array II | [D]binary-search | rotated sorted array | Python | |
146 | O | 153. Find Minimum in Rotated Sorted Array | [D]binary-search | rotated sorted array | Python |
147 | heap note |
[E]heap | |||
148 | O | 1235. Maximum Profit in Job Scheduling | [E]heap | greedily schedule tasks (start/end/val) | Python |
149 | 646. Maximum Length of Pair Chain | [E]heap | greedily schedule tasks (start/end/val) | Python | |
150 | 2008. Maximum Earnings From Taxi | [E]heap | greedily schedule tasks (start/end/val) | Python | |
151 | 2054. Two Best Non-Overlapping Events | [E]heap | greedily schedule tasks (start/end/val) | Python | |
152 | O | 973. K Closest Points to Origin | [E]heap | top k problem (based on heap) | Python Java |
153 | O | 692. Top K Frequent Words | [E]heap | top k problem (based on heap) | Python |
154 | 264. Ugly Number II | [E]heap | k way merge problem | Python | |
155 | 313. Super Ugly Number | [E]heap | k way merge problem | Python | |
156 | 355. Design Twitter | [E]heap | k way merge problem | Python | |
157 | O | 759. Employee Free Time | [E]heap | k way merge problem | Python |
158 | O | 632. Smallest Range Covering Elements from K Lists | [E]heap | k way merge problem | Python |
159 | O | 23. Merge k Sorted Lists | [E]heap | k way merge problem | Python |
160 | O | 295. Find Median from Data Stream | [E]heap | two heap problem | Python |
161 | 502. IPO | [E]heap | two heap problem | Python | |
162 | 480. Sliding Window Median | [E]heap | two heap problem | Python | |
163 | 1383. Maximum Performance of a Team | [E]heap | storing and popping out elements | Python | |
164 | 630. Course Schedule III | [E]heap | storing and popping out elements | Python | |
165 | 1094. Car Pooling | [E]heap | storing and popping out elements | Python | |
166 | 1705. Maximum Number of Eaten Apples | [E]heap | storing and popping out elements | Python | |
167 | 1792. Maximum Average Pass Ratio | [E]heap | storing and popping out elements | Python | |
168 | 378. Kth Smallest Element in a Sorted Matrix | [E]heap | use bfs and heap | Python | |
169 | 373. Find K Pairs with Smallest Sums | [E]heap | use bfs and heap | Python | |
170 | 407. Trapping Rain Water II | [E]heap | use bfs and heap | Python | |
171 | string note |
[F]string | |||
172 | O | 844. Backspace String Compare | [F]string | traverse from end | Python Java |
173 | 43. Multiply Strings | [F]string | traverse from end | Python | |
174 | 58. Length of Last Word | [F]string | traverse from end | Python | |
175 | O | 8. String to Integer (atoi) | [F]string | handle value’s bound | Python Java |
176 | O | 271. Encode and Decode Strings | [F]string | use chunk | Python |
177 | 28. Find the Index of the First Occurrence in a String | [F]string | use rabin karp (rolling hash) | Python | |
178 | 187. Repeated DNA Sequences | [F]string | use rabin karp (rolling hash) | Python | |
179 | 1044. Longest Duplicate Substring | [F]string | use rabin karp (rolling hash) | Python | |
180 | 718. Maximum Length of Repeated Subarray | [F]string | use rabin karp (rolling hash) | Python | |
181 | O | 14. Longest Common Prefix | [F]string | string composition | Python Java |
182 | 273. Integer to English Words | [F]string | string composition | Python | |
183 | 68. Text Justification | [F]string | string composition | Python | |
184 | 65. Valid Number | [F]string | string composition | Python | |
185 | 6. Zigzag Conversion | [F]string | string composition | Python | |
186 | trie note |
[G]trie | |||
187 | O | 208. Implement Trie (Prefix Tree) | [G]trie | standard trie | Python Java |
188 | O | 588. Design In-Memory File System | [G]trie | custom trie node | Python |
189 | 1268. Search Suggestions System | [G]trie | custom trie node | Python | |
190 | 2185. Counting Words With a Given Prefix | [G]trie | custom trie node | Python | |
191 | 2416. Sum of Prefix Scores of Strings | [G]trie | custom trie node | Python | |
192 | 745. Prefix and Suffix Search | [G]trie | custom trie node | Python | |
193 | 1166. Design File System | [G]trie | custom trie node | Python | |
194 | O | 211. Design Add and Search Words Data Structure | [G]trie | perform dfs inside trie | Python |
195 | 472. Concatenated Words | [G]trie | perform dfs inside trie | Python | |
196 | 642. Design Search Autocomplete System | [G]trie | perform dfs inside trie | Python | |
197 | array note |
[H]array | |||
198 | 243. Shortest Word Distance | [H]array | traverse | Python | |
199 | O | 169. Majority Element | [H]array | use boyer moore vote algorithm | Python Java |
200 | 229. Majority Element II | [H]array | use boyer moore vote algorithm | Python | |
201 | O | 189. Rotate Array | [H]array | use reverse technique | Python |
202 | O | 362. Design Hit Counter | [H]array | use circular array | Python |
203 | O | 41. First Missing Positive | [H]array | specific range array (cyclic sort) | Python |
204 | 442. Find All Duplicates in an Array | [H]array | specific range array (cyclic sort) | Python | |
205 | 448. Find All Numbers Disappeared in an Array | [H]array | specific range array (cyclic sort) | Python | |
206 | O | 287. Find the Duplicate Number | [H]array | specific range array (cycle detection) | Python |
207 | 845. Longest Mountain in Array | [H]array | use finite state machine | Python | |
208 | 370. Range Addition | [H]array | use difference array | Python | |
209 | 849. Maximize Distance to Closest Person | [H]array | count continuous elements | Python | |
210 | 384. Shuffle an Array | [H]array | use knuth shuffle | Python | |
211 | 398. Random Pick Index | [H]array | use reservoir sampling | Python | |
212 | 1535. Find the Winner of an Array Game | [H]array | simulation | Python | |
213 | 280. Wiggle Sort | [H]array | use swap | Python | |
214 | 1472. Design Browser History | [H]array | maintain array's range dynamically | Python | |
215 | 163. Missing Ranges | [H]array | pre-process the array | Python | |
216 | O | 56. Merge Intervals | [H]array-line-sweep | compare two intervals each round | Python Java |
217 | O | 57. Insert Interval | [H]array-line-sweep | compare two intervals each round | Python Java |
218 | 1272. Remove Interval | [H]array-line-sweep | compare two intervals each round | Python | |
219 | O | 252. Meeting Rooms | [H]array-line-sweep | compare two intervals each round | Python Java |
220 | O | 435. Non-overlapping Intervals | [H]array-line-sweep | compare two intervals each round | Python |
221 | 1288. Remove Covered Intervals | [H]array-line-sweep | compare two intervals each round | Python | |
222 | 452. Minimum Number of Arrows to Burst Balloons | [H]array-line-sweep | compare two intervals each round | Python | |
223 | 757. Set Intersection Size At Least Two | [H]array-line-sweep | compare two intervals each round | Python | |
224 | 986. Interval List Intersections | [H]array-line-sweep | compare two intervals each round | Python | |
225 | 1229. Meeting Scheduler | [H]array-line-sweep | compare two intervals each round | Python | |
226 | O | 253. Meeting Rooms II | [H]array-line-sweep | use heap to store previous intervals’ states | Python |
227 | 1851. Minimum Interval to Include Each Query | [H]array-line-sweep | use heap to store previous intervals’ states | Python | |
228 | 303. Range Sum Query - Immutable | [H]array-prefix-sum | use standard prefix sum | Python | |
229 | 304. Range Sum Query 2D - Immutable | [H]array-prefix-sum | use standard prefix sum | Python | |
230 | O | 238. Product of Array Except Self | [H]array-prefix-sum | use standard prefix sum | Python Java |
231 | 724. Find Pivot Index | [H]array-prefix-sum | use standard prefix sum | Python | |
232 | 2256. Minimum Average Difference | [H]array-prefix-sum | use standard prefix sum | Python | |
233 | 2100. Find Good Days to Rob the Bank | [H]array-prefix-sum | use standard prefix sum | Python | |
234 | 2055. Plates Between Candles | [H]array-prefix-sum | use standard prefix sum | Python | |
235 | 1031. Maximum Sum of Two Non-Overlapping Subarrays | [H]array-prefix-sum | use standard prefix sum | Python | |
236 | O | 560. Subarray Sum Equals K | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python Java |
237 | O | 525. Contiguous Array | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python |
238 | 974. Subarray Sums Divisible by K | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
239 | 523. Continuous Subarray Sum | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
240 | 325. Maximum Size Subarray Sum Equals k | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
241 | 1248. Count Number of Nice Subarrays | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
242 | 363. Max Sum of Rectangle No Larger Than K | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
243 | 548. Split Array with Equal Sum | [H]array-prefix-sum | use hashmap to validate the gap subarray | Python | |
244 | O | 3. Longest Substring Without Repeating Characters | [H]array-sliding-window | use standard sliding window | Python Java |
245 | 567. Permutation in String | [H]array-sliding-window | use standard sliding window | Python | |
246 | O | 438. Find All Anagrams in a String | [H]array-sliding-window | use standard sliding window | Python Java |
247 | O | 424. Longest Repeating Character Replacement | [H]array-sliding-window | use standard sliding window | Python Java |
248 | 1151. Minimum Swaps to Group All 1's Together | [H]array-sliding-window | use standard sliding window | Python | |
249 | 2134. Minimum Swaps to Group All 1's Together II | [H]array-sliding-window | use standard sliding window | Python | |
250 | 340. Longest Substring with At Most K Distinct Characters | [H]array-sliding-window | use standard sliding window | Python | |
251 | 1100. Find K-Length Substrings With No Repeated Characters | [H]array-sliding-window | use standard sliding window | Python | |
252 | 904. Fruit Into Baskets | [H]array-sliding-window | use standard sliding window | Python | |
253 | 1423. Maximum Points You Can Obtain from Cards | [H]array-sliding-window | use standard sliding window | Python | |
254 | 30. Substring with Concatenation of All Words | [H]array-sliding-window | use standard sliding window | Python | |
255 | 395. Longest Substring with At Least K Repeating Characters | [H]array-sliding-window | use standard sliding window | Python | |
256 | O | 76. Minimum Window Substring | [H]array-sliding-window | use shrink type sliding window | Python |
257 | 209. Minimum Size Subarray Sum | [H]array-sliding-window | use shrink type sliding window | Python | |
258 | O | 121. Best Time to Buy and Sell Stock | [H]array-two-pointers-same-direction | use left ptr to record | Python Java |
259 | 122. Best Time to Buy and Sell Stock II | [H]array-two-pointers-same-direction | use left ptr to record | Python | |
260 | O | 283. Move Zeroes | [H]array-two-pointers-same-direction | use left ptr to record | Python Java |
261 | 27. Remove Element | [H]array-two-pointers-same-direction | use left ptr to record | Python | |
262 | 26. Remove Duplicates from Sorted Array | [H]array-two-pointers-same-direction | use left ptr to record | Python | |
263 | 80. Remove Duplicates from Sorted Array II | [H]array-two-pointers-same-direction | use left ptr to record | Python | |
264 | O | 75. Sort Colors | [H]array-two-pointers-same-direction | use left ptr to record | Python Java |
265 | 2414. Length of the Longest Alphabetical Continuous Substring | [H]array-two-pointers-same-direction | use left ptr to record | Python | |
266 | O | 31. Next Permutation | [H]array-two-pointers-same-direction | find next permutation | Python |
267 | 556. Next Greater Element III | [H]array-two-pointers-same-direction | find next permutation | Python | |
268 | 165. Compare Version Numbers | [H]array-two-pointers-same-direction | traverse two sequences | Python | |
269 | 2337. Move Pieces to Obtain a String | [H]array-two-pointers-same-direction | traverse two sequences | Python | |
270 | 1574. Shortest Subarray to be Removed to Make Array Sorted | [H]array-two-pointers-same-direction | traverse two sequences | Python | |
271 | 244. Shortest Word Distance II | [H]array-two-pointers-same-direction | traverse two sequences | Python | |
272 | 167. Two Sum II - Input Array Is Sorted | [H]array-two-pointers-opposite-direction | use shrink type | Python | |
273 | O | 15. 3Sum | [H]array-two-pointers-opposite-direction | use shrink type | Python Java |
274 | 18. 4Sum | [H]array-two-pointers-opposite-direction | use shrink type | Python | |
275 | O | 16. 3Sum Closest | [H]array-two-pointers-opposite-direction | use shrink type | Python |
276 | O | 977. Squares of a Sorted Array | [H]array-two-pointers-opposite-direction | use shrink type | Python Java |
277 | O | 11. Container With Most Water | [H]array-two-pointers-opposite-direction | use shrink type | Python Java |
278 | O | 42. Trapping Rain Water | [H]array-two-pointers-opposite-direction | use shrink type | Python |
279 | 948. Bag of Tokens | [H]array-two-pointers-opposite-direction | use shrink type | Python | |
280 | O | 125. Valid Palindrome | [H]array-two-pointers-opposite-direction | use shrink type | Python Java |
281 | 680. Valid Palindrome II | [H]array-two-pointers-opposite-direction | use shrink type | Python | |
282 | 344. Reverse String | [H]array-two-pointers-opposite-direction | use shrink type | Python Java | |
283 | 151. Reverse Words in a String | [H]array-two-pointers-opposite-direction | use shrink type | Python | |
284 | O | 5. Longest Palindromic Substring | [H]array-two-pointers-opposite-direction | use expand type | Python Java |
285 | O | 179. Largest Number | [H]array-sort | use self defined sort | Python |
286 | O | 215. Kth Largest Element in an Array | [H]array-sort | top k problem (based on sort) | Python Java |
287 | 347. Top K Frequent Elements | [H]array-sort | top k problem (based on sort) | Python Java | |
288 | 1985. Find the Kth Largest Integer in the Array | [H]array-sort | top k problem (based on sort) | Python | |
289 | 1710. Maximum Units on a Truck | [H]array-sort | use bucket sort | Python | |
290 | 451. Sort Characters By Frequency | [H]array-sort | use bucket sort | Python | |
291 | 1099. Two Sum Less Than K | [H]array-sort | use bucket sort | Python | |
292 | 164. Maximum Gap | [H]array-sort | use bucket sort | Python | |
293 | 462. Minimum Moves to Equal Array Elements II | [H]array-sort | use quick select | Python | |
294 | 324. Wiggle Sort II | [H]array-sort | use quick select | Python | |
295 | 315. Count of Smaller Numbers After Self | [H]array-sort | use merge sort | Python | |
296 | 493. Reverse Pairs | [H]array-sort | use merge sort | Python | |
297 | stack-queue note |
[I]stack-queue | |||
298 | 346. Moving Average from Data Stream | [I]stack-queue | use queue to simulate | Python | |
299 | O | 20. Valid Parentheses | [I]stack-queue | use stack to store the last states | Python Java |
300 | O | 150. Evaluate Reverse Polish Notation | [I]stack-queue | use stack to store the last states | Python Java |
301 | O | 224. Basic Calculator | [I]stack-queue | use stack to store the last states | Python |
302 | O | 227. Basic Calculator II | [I]stack-queue | use stack to store the last states | Python |
303 | 772. Basic Calculator III | [I]stack-queue | use stack to store the last states | Python | |
304 | O | 735. Asteroid Collision | [I]stack-queue | use stack to store the last states | Python |
305 | O | 394. Decode String | [I]stack-queue | use stack to store the last states | Python |
306 | 1209. Remove All Adjacent Duplicates in String II | [I]stack-queue | use stack to store the last states | Python | |
307 | 726. Number of Atoms | [I]stack-queue | use stack to store the last states | Python | |
308 | 71. Simplify Path | [I]stack-queue | use stack to store the last states | Python | |
309 | O | 232. Implement Queue using Stacks | [I]stack-queue | implement stack/queue | Python Java |
310 | 225. Implement Stack using Queues | [I]stack-queue | implement stack/queue | Python | |
311 | O | 155. Min Stack | [I]stack-queue | implement stack/queue | Python Java |
312 | 716. Max Stack | [I]stack-queue | implement stack/queue | Python | |
313 | O | 895. Maximum Frequency Stack | [I]stack-queue | implement stack/queue | Python |
314 | O | 32. Longest Valid Parentheses | [I]stack-queue | use variables to simulate stack | Python |
315 | 1249. Minimum Remove to Make Valid Parentheses | [I]stack-queue | use variables to simulate stack | Python | |
316 | 2296. Design a Text Editor | [I]stack-queue | use stack to simulate | Python | |
317 | 341. Flatten Nested List Iterator | [I]stack-queue | use stack to simulate | Python | |
318 | O | 239. Sliding Window Maximum | [I]stack-queue-monotonic | use monotonic queue and sliding window | Python |
319 | 1438. Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | [I]stack-queue-monotonic | use monotonic queue and sliding window | Python | |
320 | 1696. Jump Game VI | [I]stack-queue-monotonic | use monotonic queue and sliding window | Python | |
321 | 862. Shortest Subarray with Sum at Least K | [I]stack-queue-monotonic | use monotonic queue and sliding window | Python | |
322 | O | 739. Daily Temperatures | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python Java |
323 | 496. Next Greater Element I | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
324 | 503. Next Greater Element II | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
325 | 402. Remove K Digits | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
326 | 316. Remove Duplicate Letters | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
327 | 1762. Buildings With an Ocean View | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
328 | 1944. Number of Visible People in a Queue | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
329 | 2345. Finding the Number of Visible Mountains | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
330 | 768. Max Chunks To Make Sorted II | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
331 | 2289. Steps to Make Array Non-decreasing | [I]stack-queue-monotonic | use monotonic stack (consider one side’s relationship) | Python | |
332 | O | 84. Largest Rectangle in Histogram | [I]stack-queue-monotonic | use monotonic stack (consider two side’s relationship) | Python |
333 | 85. Maximal Rectangle | [I]stack-queue-monotonic | use monotonic stack (consider two side’s relationship) | Python | |
334 | 907. Sum of Subarray Minimums | [I]stack-queue-monotonic | use monotonic stack (consider two side’s relationship) | Python | |
335 | 2104. Sum of Subarray Ranges | [I]stack-queue-monotonic | use monotonic stack (consider two side’s relationship) | Python | |
336 | 1856. Maximum Subarray Min-Product | [I]stack-queue-monotonic | use monotonic stack (consider two side’s relationship) | Python | |
337 | backtracking note |
[J]backtracking | |||
338 | O | 78. Subsets | [J]backtracking | subset | Python Java |
339 | O | 39. Combination Sum | [J]backtracking | subset | Python Java |
340 | 90. Subsets II | [J]backtracking | subset | Python | |
341 | 40. Combination Sum II | [J]backtracking | subset | Python | |
342 | O | 46. Permutations | [J]backtracking | permutation | Python Java |
343 | 47. Permutations II | [J]backtracking | permutation | Python | |
344 | 267. Palindrome Permutation II | [J]backtracking | permutation | Python | |
345 | 77. Combinations | [J]backtracking | combination | Python | |
346 | 216. Combination Sum III | [J]backtracking | combination | Python | |
347 | O | 17. Letter Combinations of a Phone Number | [J]backtracking | backtracking with constraints | Python Java |
348 | O | 22. Generate Parentheses | [J]backtracking | backtracking with constraints | Python |
349 | O | 113. Path Sum II | [J]backtracking | backtracking with constraints | Python |
350 | O | 437. Path Sum III | [J]backtracking | backtracking with constraints | Python |
351 | O | 79. Word Search | [J]backtracking | backtracking with constraints | Python Java |
352 | O | 212. Word Search II | [J]backtracking | backtracking with constraints | Python |
353 | O | 37. Sudoku Solver | [J]backtracking | backtracking with constraints | Python |
354 | O | 51. N-Queens | [J]backtracking | backtracking with constraints | Python |
355 | 465. Optimal Account Balancing | [J]backtracking | backtracking with constraints | Python | |
356 | 93. Restore IP Addresses | [J]backtracking | backtracking with constraints | Python | |
357 | 140. Word Break II | [J]backtracking | backtracking with constraints | Python | |
358 | 257. Binary Tree Paths | [J]backtracking | backtracking with constraints | Python | |
359 | 131. Palindrome Partitioning | [J]backtracking | backtracking with constraints | Python | |
360 | graph note |
[K]graph | |||
361 | O | 329. Longest Increasing Path in a Matrix | [K]graph-dfs | dfs | Python |
362 | 1059. All Paths from Source Lead to Destination | [K]graph-dfs | dfs | Python | |
363 | O | 200. Number of Islands | [K]graph-bfs | bfs with single source | Python Java |
364 | O | 733. Flood Fill | [K]graph-bfs | bfs with single source | Python Java |
365 | O | 1730. Shortest Path to Get Food | [K]graph-bfs | bfs with single source | Python |
366 | O | 1197. Minimum Knight Moves | [K]graph-bfs | bfs with single source | Python |
367 | O | 261. Graph Valid Tree | [K]graph-bfs | bfs with single source | Python |
368 | O | 127. Word Ladder | [K]graph-bfs | bfs with single source | Python |
369 | O | 133. Clone Graph | [K]graph-bfs | bfs with single source | Python Java |
370 | O | 815. Bus Routes | [K]graph-bfs | bfs with single source | Python |
371 | 695. Max Area of Island | [K]graph-bfs | bfs with single source | Python | |
372 | 1905. Count Sub Islands | [K]graph-bfs | bfs with single source | Python | |
373 | 1345. Jump Game IV | [K]graph-bfs | bfs with single source | Python | |
374 | 1091. Shortest Path in Binary Matrix | [K]graph-bfs | bfs with single source | Python | |
375 | 1992. Find All Groups of Farmland | [K]graph-bfs | bfs with single source | Python | |
376 | 909. Snakes and Ladders | [K]graph-bfs | bfs with single source | Python | |
377 | 749. Contain Virus | [K]graph-bfs | bfs with single source | Python | |
378 | 694. Number of Distinct Islands | [K]graph-bfs | bfs with single source | Python | |
379 | O | 542. 01 Matrix | [K]graph-bfs | bfs with multiple sources | Python Java |
380 | O | 417. Pacific Atlantic Water Flow | [K]graph-bfs | bfs with multiple sources | Python |
381 | O | 994. Rotting Oranges | [K]graph-bfs | bfs with multiple sources | Python Java |
382 | 286. Walls and Gates | [K]graph-bfs | bfs with multiple sources | Python | |
383 | 130. Surrounded Regions | [K]graph-bfs | bfs with multiple sources | Python | |
384 | 126. Word Ladder II | [K]graph-bfs | bfs with hashset as queue | Python | |
385 | 301. Remove Invalid Parentheses | [K]graph-bfs | bfs with hashset as queue | Python | |
386 | O | 721. Accounts Merge | [K]graph-union-find | union find | Python Java |
387 | O | 323. Number of Connected Components in an Undirected Graph | [K]graph-union-find | union find | Python |
388 | 547. Number of Provinces | [K]graph-union-find | union find | Python | |
389 | 2316. Count Unreachable Pairs of Nodes in an Undirected Graph | [K]graph-union-find | union find | Python | |
390 | 399. Evaluate Division | [K]graph-union-find | union find | Python | |
391 | 305. Number of Islands II | [K]graph-union-find | union find | Python | |
392 | 1101. The Earliest Moment When Everyone Become Friends | [K]graph-union-find | union find | Python | |
393 | 2421. Number of Good Paths | [K]graph-union-find | union find | Python | |
394 | 1102. Path With Maximum Minimum Value | [K]graph-union-find | union find | Python | |
395 | 737. Sentence Similarity II | [K]graph-union-find | union find | Python | |
396 | O | 207. Course Schedule | [K]graph-kahn | kahn (topological sort) | Python Java |
397 | O | 210. Course Schedule II | [K]graph-kahn | kahn (topological sort) | Python |
398 | O | 269. Alien Dictionary | [K]graph-kahn | kahn (topological sort) | Python |
399 | O | 310. Minimum Height Trees | [K]graph-kahn | kahn (topological sort) | Python Java |
400 | 2115. Find All Possible Recipes from Given Supplies | [K]graph-kahn | kahn (topological sort) | Python | |
401 | 802. Find Eventual Safe States | [K]graph-kahn | kahn (topological sort) | Python | |
402 | 1136. Parallel Courses | [K]graph-kahn | kahn (topological sort) | Python | |
403 | 2050. Parallel Courses III | [K]graph-kahn | kahn (topological sort) | Python | |
404 | 1203. Sort Items by Groups Respecting Dependencies | [K]graph-kahn | kahn (topological sort) | Python | |
405 | 2192. All Ancestors of a Node in a Directed Acyclic Graph | [K]graph-kahn | kahn (topological sort) | Python | |
406 | 743. Network Delay Time | [K]graph-dijkstra | dijkstra (shortest path) | Python | |
407 | 778. Swim in Rising Water | [K]graph-dijkstra | dijkstra (shortest path) | Python | |
408 | 1514. Path with Maximum Probability | [K]graph-dijkstra | dijkstra (shortest path) | Python | |
409 | 505. The Maze II | [K]graph-dijkstra | dijkstra (shortest path) | Python | |
410 | 2093. Minimum Cost to Reach City With Discounts | [K]graph-dijkstra | dijkstra (shortest path) | Python | |
411 | O | 787. Cheapest Flights Within K Stops | [K]graph-bellman-ford | bellman ford (shortest path) | Python |
412 | 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance | [K]graph-floyd-warshall | floyd warshall (shortest path) | Python | |
413 | 1135. Connecting Cities With Minimum Cost | [K]graph-kruskal | kruskal (mst) | Python | |
414 | 1584. Min Cost to Connect All Points | [K]graph-kruskal | kruskal (mst) | Python | |
415 | 1168. Optimize Water Distribution in a Village | [K]graph-kruskal | kruskal (mst) | Python | |
416 | 1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree | [K]graph-kruskal | kruskal (mst) | Python | |
417 | 1724. Checking Existence of Edge Length Limited Paths II | [K]graph-kruskal | kruskal (mst) | Python | |
418 | 1192. Critical Connections in a Network | [K]graph-tarjan | tarjan (scc) | Python | |
419 | 332. Reconstruct Itinerary | [K]graph-hierholzer | hierholzer (eulerian path) | Python | |
420 | 753. Cracking the Safe | [K]graph-hierholzer | hierholzer (eulerian path) | Python | |
421 | O | 54. Spiral Matrix | [K]graph-matrix | matrix | Python Java |
422 | O | 48. Rotate Image | [K]graph-matrix | matrix | Python |
423 | O | 73. Set Matrix Zeroes | [K]graph-matrix | matrix | Python |
424 | 1582. Special Positions in a Binary Matrix | [K]graph-matrix | matrix | Python | |
425 | 348. Design Tic-Tac-Toe | [K]graph-matrix | matrix | Python | |
426 | bit-manipulation note |
[L]bit-manipulation | |||
427 | O | 136. Single Number | [L]bit-manipulation | xor | Python Java |
428 | O | 268. Missing Number | [L]bit-manipulation | xor | Python Java |
429 | O | 191. Number of 1 Bits | [L]bit-manipulation | shift | Python Java |
430 | O | 190. Reverse Bits | [L]bit-manipulation | shift | Python Java |
431 | 1356. Sort Integers by The Number of 1 Bits | [L]bit-manipulation | shift | Python | |
432 | O | 36. Valid Sudoku | [L]bit-manipulation | bitmasking | Python |
433 | 1915. Number of Wonderful Substrings | [L]bit-manipulation | bitmasking | Python | |
434 | 1542. Find Longest Awesome Substring | [L]bit-manipulation | bitmasking | Python | |
435 | dynamic-programming note |
[M]dynamic-programming | |||
436 | O | 62. Unique Paths | [M]dynamic-programming | 2D | Python Java |
437 | 63. Unique Paths II | [M]dynamic-programming | 2D | Python | |
438 | O | 221. Maximal Square | [M]dynamic-programming | 2D | Python |
439 | 64. Minimum Path Sum | [M]dynamic-programming | 2D | Python | |
440 | 688. Knight Probability in Chessboard | [M]dynamic-programming | 2D | Python | |
441 | O | 416. Partition Equal Subset Sum | [M]dynamic-programming | knapsack (0-1 knapsack) | Python Java |
442 | 494. Target Sum | [M]dynamic-programming | knapsack (0-1 knapsack) | Python | |
443 | 1049. Last Stone Weight II | [M]dynamic-programming | knapsack (0-1 knapsack) | Python | |
444 | 474. Ones and Zeroes | [M]dynamic-programming | knapsack (0-1 knapsack) | Python | |
445 | O | 322. Coin Change | [M]dynamic-programming | knapsack (complete knapsack) | Python Java |
446 | 279. Perfect Squares | [M]dynamic-programming | knapsack (complete knapsack) | Python | |
447 | 518. Coin Change II | [M]dynamic-programming | knapsack (combination knapsack) | Python | |
448 | O | 377. Combination Sum IV | [M]dynamic-programming | knapsack (permutation knapsack) | Python |
449 | O | 70. Climbing Stairs | [M]dynamic-programming | linear sequence | Python Java |
450 | O | 55. Jump Game | [M]dynamic-programming | linear sequence | Python |
451 | O | 198. House Robber | [M]dynamic-programming | linear sequence | Python Java |
452 | 213. House Robber II | [M]dynamic-programming | linear sequence | Python | |
453 | O | 152. Maximum Product Subarray | [M]dynamic-programming | linear sequence | Python |
454 | O | 91. Decode Ways | [M]dynamic-programming | linear sequence | Python |
455 | O | 139. Word Break | [M]dynamic-programming | linear sequence | Python Java |
456 | 256. Paint House | [M]dynamic-programming | linear sequence | Python | |
457 | 123. Best Time to Buy and Sell Stock III | [M]dynamic-programming | linear sequence | Python | |
458 | 309. Best Time to Buy and Sell Stock with Cooldown | [M]dynamic-programming | linear sequence | Python | |
459 | 376. Wiggle Subsequence | [M]dynamic-programming | linear sequence | Python | |
460 | 487. Max Consecutive Ones II | [M]dynamic-programming | linear sequence | Python | |
461 | 368. Largest Divisible Subset | [M]dynamic-programming | linear sequence | Python | |
462 | 1105. Filling Bookcase Shelves | [M]dynamic-programming | linear sequence | Python | |
463 | O | 300. Longest Increasing Subsequence | [M]dynamic-programming | LIS | Python |
464 | 1964. Find the Longest Valid Obstacle Course at Each Position | [M]dynamic-programming | LIS | Python | |
465 | 354. Russian Doll Envelopes | [M]dynamic-programming | LIS | Python | |
466 | 1143. Longest Common Subsequence | [M]dynamic-programming | double sequence | Python | |
467 | 72. Edit Distance | [M]dynamic-programming | double sequence | Python | |
468 | 97. Interleaving String | [M]dynamic-programming | double sequence | Python | |
469 | 115. Distinct Subsequences | [M]dynamic-programming | double sequence | Python | |
470 | 1092. Shortest Common Supersequence | [M]dynamic-programming | double sequence | Python | |
471 | 10. Regular Expression Matching | [M]dynamic-programming | double sequence | Python | |
472 | 410. Split Array Largest Sum | [M]dynamic-programming | interval (start from one interval) | Python | |
473 | 1335. Minimum Difficulty of a Job Schedule | [M]dynamic-programming | interval (start from one interval) | Python | |
474 | 1278. Palindrome Partitioning III | [M]dynamic-programming | interval (start from one interval) | Python | |
475 | 312. Burst Balloons | [M]dynamic-programming | interval (start from short interval) | Python | |
476 | 516. Longest Palindromic Subsequence | [M]dynamic-programming | interval (start from short interval) | Python | |
477 | 647. Palindromic Substrings | [M]dynamic-programming | interval (start from short interval) | Python | |
478 | 1547. Minimum Cost to Cut a Stick | [M]dynamic-programming | interval (start from short interval) | Python | |
479 | greedy note |
[N]greedy | |||
480 | O | 53. Maximum Subarray | [N]greedy | greedy | Python Java |
481 | O | 134. Gas Station | [N]greedy | greedy | Python Java |
482 | O | 621. Task Scheduler | [N]greedy | greedy | Python Java |
483 | 45. Jump Game II | [N]greedy | greedy | Python | |
484 | 665. Non-decreasing Array | [N]greedy | greedy | Python | |
485 | 135. Candy | [N]greedy | greedy | Python | |
486 | 277. Find the Celebrity | [N]greedy | greedy | Python | |
487 | 406. Queue Reconstruction by Height | [N]greedy | greedy | Python | |
488 | 659. Split Array into Consecutive Subsequences | [N]greedy | greedy | Python | |
489 | 763. Partition Labels | [N]greedy | greedy | Python | |
490 | 926. Flip String to Monotone Increasing | [N]greedy | greedy | Python | |
491 | 1567. Maximum Length of Subarray With Positive Product | [N]greedy | greedy | Python | |
492 | 1864. Minimum Number of Swaps to Make the Binary String Alternating | [N]greedy | greedy | Python | |
493 | 2366. Minimum Replacements to Sort the Array | [N]greedy | greedy | Python | |
494 | 2870. Minimum Number of Operations to Make Array Empty | [N]greedy | greedy | Python | |
495 | math note |
[O]math | |||
496 | 204. Count Primes | [O]math | sieve of eratosthenes | Python | |
497 | O | 50. Pow(x, n) | [O]math | exponentiation by squaring | Python |
498 | 470. Implement Rand10() Using Rand7() | [O]math | rejection sampling | Python | |
499 | O | 7. Reverse Integer | [O]math | math | Python |
500 | O | 9. Palindrome Number | [O]math | math | Python Java |
501 | O | 67. Add Binary | [O]math | math | Python Java |
502 | O | 338. Counting Bits | [O]math | math | Python Java |
503 | 415. Add Strings | [O]math | math | Python | |
504 | 263. Ugly Number | [O]math | math | Python | |
505 | 258. Add Digits | [O]math | math | Python | |
506 | 171. Excel Sheet Column Number | [O]math | math | Python | |
507 | 869. Reordered Power of 2 | [O]math | math | Python | |
508 | 391. Perfect Rectangle | [O]math | math | Python | |
509 | segment-tree note |
[P]segment-tree | |||
510 | 307. Range Sum Query - Mutable | [P]segment-tree | use sum type segment tree | Python | |
511 | 715. Range Module | [P]segment-tree | use count type segment tree | Python | |
512 | 729. My Calendar I | [P]segment-tree | use count type segment tree | Python | |
513 | 2158. Amount of New Area Painted Each Day | [P]segment-tree | use count type segment tree | Python | |
514 | 218. The Skyline Problem | [P]segment-tree | use max type segment tree | Python | |
515 | 2407. Longest Increasing Subsequence II | [P]segment-tree | use max type segment tree | Python | |
516 | 731. My Calendar II | [P]segment-tree | use max type segment tree | Python | |
517 | basic note |
[Q]basic |
How to crack LeetCode problems?
-
For beginners tackling 0-50 problems, I suggest starting with curated lists like the Blind 75, Grind 75, or NeetCode 150. It's crucial to begin with EASY problems. If you stumble upon unfamiliar concepts, don't hesitate to seek explanations from sources like ChatGPT or the LeetCode discussion section. Aim to accomplish three key objectives during this phase: familiarize yourself with the syntax of common data structures like hashmaps or stacks, gain a holistic understanding of necessary DSA topics, and grasp at least the brute force solution approach, along with basic analyses of time and space complexity for each problem.
-
For intermediates solving 50-150 problems, understanding how and why to evolve from brute force to more efficient or optimal solutions is vital. Grasping this transition process is crucial, not just memorizing solutions. At this stage, deeply comprehending the improvement mechanism is the key focus. Often, the breakpoint for a better solution comes from identifying and refining repetitive elements in the old approach.
-
After solving over 150 problems, you'll likely have covered around 85% of the topics that could appear in coding interviews. The key at this phase is to recognize patterns across the multitude of problems available. Most questions are variations of a few core concepts or classic problems you've already encountered. Identifying these patterns allows you to apply known solutions to new, seemingly complex problems effectively. Additionally, you should start using different approaches to solve the same problem you already know. For example, if it is a DFS problem, then try both recursive and iterative methods; if it is a DP problem, try both top-down and bottom-up approaches; if it is a top-k problem, then try using a heap or sort. Furthermore, attempt to understand other solutions that use approaches that are not as straightforward as your old solutions. At this stage, it's crucial to recognize recurring patterns across various problems, understanding both the application of consistent approaches to different questions and the exploration of multiple strategies for a single problem. This dual awareness enables a more adaptable and comprehensive problem-solving skill set.
How to prepare for a coding interview?
During the interview, consistently share your thoughts with the interviewer and use code comments to note down things while speaking. This ensures both of you are aligned.
-
Clarify the requirement of the question
. You must truly understand what the question is asking for. Once you understand the question’s description, make sure to generate a simple input and expect output other than the given one based on your understanding and ask the interviewer if it is correct or not. -
Clarify the input and output and edge cases
. For instance, ask if the input array is sorted or not, whether numbers can include positives, negatives, or zeros, or if the input contains duplicate elements or not, and how to handle multiple valid answers, whether to return the first one or if outputs need sorting, and what is the expected outcome when there are no valid solutions. Take LC 209. Minimum Size Subarray Sum as example, if numbers in the input array can be negative, the question will become LC 862. Shortest Subarray with Sum at Least K, and will need a totally different approach to solve. -
Start from a brute force approach
, just write some very simple pseudo steps of it. If you have ideas to improve it, then you can continue to explain how and where you can improve and use which DSA or classic pattern (like prefix sum, trie, or two pointers) to solve it. Mention the expected time and space complexity. If you do not have any clue to improve the naive approach, then just ask the interviewer, can we start from implementing this naive approach or not, sometimes you would find out the key point during implementing. If it is not allowed, then try to analyze some common DSA which might be useful here to the interviewer and try to get some feedback or hints from the interviewer. (If brute force is still too hard to get, then try to simulate the whole process in the description of the question or try to enumerate things). -
Implement the solution
, adhering to proper coding style and indentation. If stuck on certain code, ask to finish the main logic first and leave comments for unimplemented parts. If stuck on the main logic, share your thoughts and discuss potential next steps with the interviewer. -
Final check and dry run
. Once finished, do not directly run the code, because there might be some stupid typos in the code. Ask if you can dry run one time, and explain the whole process and your thoughts. -
Test and debug
. Generate 1 or 2 standard cases and 1 or 2 edge cases which are related to the problem. And start testing and debugging. Avoid trial and error multiple times when debugging. Fix the error you find, and try to quickly dry run once and explain why you fix the error. -
Complexity analysis
. Try to analyze the time and space complexity about your solutions and try to mention some potential follow up questions you have thought of. Like what if we change the condition of the input, or what if we have a limitation on time or space usage.