If you often find yourself grappling with how to tackle LeetCode problems, our repo is here to assist you!
Pattern500 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 Pattern500
Pattern500 is inspired by Blind 75 and Grind 75's classic problem selection. Pattern500 offers 500 Python solutions for LeetCode, 17 notes on essential concepts related to data structures and algorithms, and multiple 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 Python skills, deepen your understanding of fundamental DSA topics, and prepare for SDE interviews.
Mind map for all patterns in Pattern500
Check our mind map in Figma.
Suggestions & Questions
Feel free to raise issues.
Num | Grind 75 | Name | Topic | Pattern | Solution |
---|---|---|---|---|---|
001 | tree | [A]tree | |||
002 | O | 100. Same Tree | [A]tree-divide-and-conquer | two branch top-down | Python |
003 | O | 101. Symmetric Tree | [A]tree-divide-and-conquer | two branch top-down | Python |
004 | O | 98. Validate Binary Search Tree | [A]tree-divide-and-conquer | two branch top-down | Python |
005 | O | 105. Construct Binary Tree from Preorder and Inorder Traversal | [A]tree-divide-and-conquer | re-build tree (top-down) | Python |
006 | 106. Construct Binary Tree from Inorder and Postorder Traversal | [A]tree-divide-and-conquer | re-build tree (top-down) | Python | |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
038 | O | 110. Balanced Binary Tree | [A]tree-dfs-postorder | postorder | Python |
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 |
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 |
048 | O | 104. Maximum Depth of Binary Tree | [A]tree-bfs | bfs | Python |
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 | [B]linked-list | |||
058 | O | 21. Merge Two Sorted Lists | [B]linked-list | use sentinel node | Python |
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 |
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 |
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 |
066 | O | 206. Reverse Linked List | [B]linked-list | use two pointers (prev and cur) | Python |
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 |
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 |
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 | [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 |
092 | O | 128. Longest Consecutive Sequence | [C]hashmap | store val | Python |
093 | O | 13. Roman to Integer | [C]hashmap | store val | Python |
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 |
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 |
104 | O | 242. Valid Anagram | [C]hashmap | store sth’s freq | Python |
105 | O | 409. Longest Palindrome | [C]hashmap | store sth’s freq | Python |
106 | 387. First Unique Character in a String | [C]hashmap | store sth’s freq | Python | |
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 |
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 | |
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 | [D]binary-search | |||
122 | O | 704. Binary Search | [D]binary-search | search in a sorted array for specific val | Python |
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 |
125 | 34. Find First and Last Position of Element in Sorted Array | [D]binary-search | search in a sorted array for specific val | Python | |
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 | |
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 |
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 |
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 |
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 | [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 |
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 | [F]string | |||
172 | O | 844. Backspace String Compare | [F]string | traverse from end | Python |
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 |
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 |
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 | [G]trie | |||
187 | O | 208. Implement Trie (Prefix Tree) | [G]trie | standard trie | Python |
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 | [H]array | |||
198 | 243. Shortest Word Distance | [H]array | traverse | Python | |
199 | O | 169. Majority Element | [H]array | use boyer moore vote algorithm | Python |
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 |
217 | O | 57. Insert Interval | [H]array-line-sweep | compare two intervals each round | Python |
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 |
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 |
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 |
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 |
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 |
247 | O | 424. Longest Repeating Character Replacement | [H]array-sliding-window | use standard sliding window | Python |
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 |
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 |
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 |
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 |
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 |
277 | O | 11. Container With Most Water | [H]array-two-pointers-opposite-direction | use shrink type | Python |
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 |
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 | |
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 |
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 |
287 | 347. Top K Frequent Elements | [H]array-sort | top k problem (based on sort) | Python | |
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 | [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 |
300 | O | 150. Evaluate Reverse Polish Notation | [I]stack-queue | use stack to store the last states | Python |
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 |
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 |
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 |
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 | [J]backtracking | |||
338 | O | 78. Subsets | [J]backtracking | subset | Python |
339 | O | 39. Combination Sum | [J]backtracking | subset | Python |
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 |
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 |
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 |
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 | [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 |
364 | O | 733. Flood Fill | [K]graph-bfs | bfs with single source | Python |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 | [L]bit-manipulation | |||
427 | O | 136. Single Number | [L]bit-manipulation | xor | Python |
428 | O | 268. Missing Number | [L]bit-manipulation | xor | Python |
429 | O | 191. Number of 1 Bits | [L]bit-manipulation | shift | Python |
430 | O | 190. Reverse Bits | [L]bit-manipulation | shift | Python |
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 | [M]dynamic-programming | |||
436 | O | 62. Unique Paths | [M]dynamic-programming | 2D | Python |
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 |
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 |
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 |
450 | O | 55. Jump Game | [M]dynamic-programming | linear sequence | Python |
451 | O | 198. House Robber | [M]dynamic-programming | linear sequence | Python |
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 | XX | [X]XX | XX | Python |
455 | O | XX | [X]XX | XX | Python |
456 | O | XX | [X]XX | XX | Python |
457 | O | XX | [X]XX | XX | Python |
458 | O | XX | [X]XX | XX | Python |
459 | O | XX | [X]XX | XX | Python |
460 | O | XX | [X]XX | XX | Python |
461 | O | XX | [X]XX | XX | Python |
462 | O | XX | [X]XX | XX | Python |
463 | O | XX | [X]XX | XX | Python |
464 | O | XX | [X]XX | XX | Python |
465 | O | XX | [X]XX | XX | Python |
466 | O | XX | [X]XX | XX | Python |
467 | O | XX | [X]XX | XX | Python |
468 | O | XX | [X]XX | XX | Python |
469 | O | XX | [X]XX | XX | Python |
470 | O | XX | [X]XX | XX | Python |
471 | O | XX | [X]XX | XX | Python |
472 | O | XX | [X]XX | XX | Python |
473 | O | XX | [X]XX | XX | Python |
474 | O | XX | [X]XX | XX | Python |
475 | O | XX | [X]XX | XX | Python |
476 | O | XX | [X]XX | XX | Python |
477 | O | XX | [X]XX | XX | Python |
478 | O | XX | [X]XX | XX | Python |
479 | greedy | [N]greedy | |||
480 | O | XX | [X]XX | XX | Python |
481 | O | XX | [X]XX | XX | Python |
482 | O | XX | [X]XX | XX | Python |
483 | O | XX | [X]XX | XX | Python |
484 | O | XX | [X]XX | XX | Python |
485 | O | XX | [X]XX | XX | Python |
486 | O | XX | [X]XX | XX | Python |
487 | O | XX | [X]XX | XX | Python |
488 | O | XX | [X]XX | XX | Python |
489 | O | XX | [X]XX | XX | Python |
490 | O | XX | [X]XX | XX | Python |
491 | O | XX | [X]XX | XX | Python |
492 | O | XX | [X]XX | XX | Python |
493 | O | XX | [X]XX | XX | Python |
494 | O | XX | [X]XX | XX | Python |
495 | math | [O]math | |||
496 | O | XX | [X]XX | XX | Python |
497 | O | XX | [X]XX | XX | Python |
498 | O | XX | [X]XX | XX | Python |
499 | O | XX | [X]XX | XX | Python |
500 | O | XX | [X]XX | XX | Python |
501 | O | XX | [X]XX | XX | Python |
502 | O | XX | [X]XX | XX | Python |
503 | O | XX | [X]XX | XX | Python |
504 | O | XX | [X]XX | XX | Python |
505 | O | XX | [X]XX | XX | Python |
506 | O | XX | [X]XX | XX | Python |
507 | O | XX | [X]XX | XX | Python |
508 | O | XX | [X]XX | XX | Python |
509 | segment-tree | [P]segment-tree | |||
510 | O | XX | [X]XX | XX | Python |
511 | O | XX | [X]XX | XX | Python |
512 | O | XX | [X]XX | XX | Python |
513 | O | XX | [X]XX | XX | Python |
514 | O | XX | [X]XX | XX | Python |
515 | O | XX | [X]XX | XX | Python |
516 | O | XX | [X]XX | XX | Python |
517 | basic | [Q]basic |