# Coding Interview Preparation [toc] ## Resource 1. [NeetCode 150](https://neetcode.io/practice) 2. [灵茶山艾府](https://github.com/EndlessCheng) (www.youtube.com/@0x3f) 3. [LeetCode Problem Rating (Chinese)](https://huxulm.github.io/lc-rating/zen) 4. [LeetCode Problem Rating](https://zerotrac.github.io/leetcode_problem_rating/#/) 5. [FAANG 面試準備經驗與建議](https://arthur-lin.medium.com/faang-%E9%9D%A2%E8%A9%A6%E6%BA%96%E5%82%99%E7%B6%93%E9%A9%97%E8%88%87%E5%BB%BA%E8%AD%B0-%E4%B8%80-b7add6a7b9a6) 6. [Coding Interview 就是刷好刷滿刷爆 LeetCode 就會上?](https://yschen25.blogspot.com/2022/02/coding-interview.html#point-7) 7. [刷1500題心路歷程](https://ikaminyou.medium.com/leetcode-%E5%88%B71500%E9%A1%8C%E5%BF%83%E8%B7%AF%E6%AD%B7%E7%A8%8B-8614284f03da) 8. [Leetcode刷題學習筆記–心得統整](https://hackmd.io/@meyr543/r1skFcvgY?utm_source=preview-mode&utm_medium=rec) 9. [面试准备经验总结](https://liuzhenglai.com/post/625131eda6983941cca711cc) 10. [Big-O Complexity Chart](https://www.bigocheatsheet.com/) 11. [CLIST](https://clist.by/resource/leetcode.com/) ## Coding Template for Remote Interview using Google Doc ``` # Assumptions or Constraints 1. 0 <= n <= 10^9 where n is the length of nums # Input 1. vector<int> nums # Output 1. bool # Examples ## Case 1. index: 0 1 2 3 4 nums : [6, 9, 8, 6, 9] ^ ^ ^ L M R ## Case 2. a -> b -> c -> g | ^ v | d -> e -> f ## Case 3. a / \ b c / \ / \ d e f g # Strategy # Complexity Time: O() Space: O() # Implementation class Solution { public: using minHeap = priority_queue<int, vector<int>, greater<int>>; Solution() : count(0) {} bool IsStrobogrammatic(vector<int>& nums) { return true; } void Helper(vector<int>& nums) { return; } private: int count; }; ``` ## Leetcode ### 1. Arrays and Hashing #### 1.1. Common [1. Two Sum](https://leetcode.com/problems/two-sum/) [31. Next Permutation](https://leetcode.com/problems/next-permutation/) [240. Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/) [128. Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) [287. Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) [442. Find All Duplicates in an Array](https://leetcode.com/problems/find-all-duplicates-in-an-array/) [792. Number of Matching Subsequences](https://leetcode.com/problems/number-of-matching-subsequences/) [41. First Missing Positive](https://leetcode.com/problems/first-missing-positive/) #### 1.2. Meet in the middle [1755. Closest Subsequence Sum](https://leetcode.com/problems/closest-subsequence-sum/) [2035. Partition Array Into Two Arrays to Minimize Sum Difference](https://leetcode.com/problems/partition-array-into-two-arrays-to-minimize-sum-difference/) ### 2. Strings [28. Find the Index of the First Occurrence in a String](https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string/) [1980. Find Unique Binary String](https://leetcode.com/problems/find-unique-binary-string/) [777. Swap Adjacent in LR String](https://leetcode.com/problems/swap-adjacent-in-lr-string/) [809. Expressive Words](https://leetcode.com/problems/expressive-words/) [844. Backspace String Compare](https://leetcode.com/problems/backspace-string-compare/) [843. Guess the Word](https://leetcode.com/problems/guess-the-word/) [564. Find the Closest Palindrome](https://leetcode.com/problems/find-the-closest-palindrome/) [1392. Longest Happy Prefix](https://leetcode.com/problems/longest-happy-prefix/) [3031. Minimum Time to Revert Word to Initial State II](https://leetcode.com/problems/minimum-time-to-revert-word-to-initial-state-ii/) [65. Valid Number (Finite State Machine)](https://leetcode.com/problems/valid-number/) ### 3. Two Pointers [845. Longest Mountain in Array](https://leetcode.com/problems/longest-mountain-in-array/description/) [167. Two Sum II - Input Array Is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) [15. 3Sum](https://leetcode.com/problems/3sum/) [11. Container With Most Water](https://leetcode.com/problems/container-with-most-water/) [42. Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) [2576. Find the Maximum Number of Marked Indices](https://leetcode.com/problems/find-the-maximum-number-of-marked-indices/) [1793. Maximum Score of a Good Subarray](https://leetcode.com/problems/maximum-score-of-a-good-subarray/) ### 4. Prefix Sum [304. Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/) [560. Subarray Sum Equals K](https://leetcode.com/problems/subarray-sum-equals-k/) [523. Continuous Subarray Sum](https://leetcode.com/problems/continuous-subarray-sum/) [1074. Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/) [437. Path Sum III](https://leetcode.com/problems/path-sum-iii/) [325. Maximum Size Subarray Sum Equals k](https://leetcode.com/problems/maximum-size-subarray-sum-equals-k/) [2448. Minimum Cost to Make Array Equal](https://leetcode.com/problems/minimum-cost-to-make-array-equal/) [548. Split Array with Equal Sum](https://leetcode.com/problems/split-array-with-equal-sum/description/) [2025. Maximum Number of Ways to Partition an Array](https://leetcode.com/problems/maximum-number-of-ways-to-partition-an-array/) [2488. Count Subarrays With Median K](https://leetcode.com/problems/count-subarrays-with-median-k/) [1371. Find the Longest Substring Containing Vowels in Even Counts](https://leetcode.com/problems/find-the-longest-substring-containing-vowels-in-even-counts/) [1542. Find Longest Awesome Substring](https://leetcode.com/problems/find-longest-awesome-substring/) [1915. Number of Wonderful Substrings](https://leetcode.com/problems/count-subarrays-with-median-k/) [2845. Count of Interesting Subarrays](https://leetcode.com/problems/count-of-interesting-subarrays/) [2949. Count Beautiful Substrings II](https://leetcode.com/problems/count-beautiful-substrings-ii/) ### 5. [Binary Search](https://youtu.be/QvcM99na30k?si=AqG8LjOg8dbbZRgh) [34. Find First and Last Position of Element in Sorted Array](https://leetcode.com/problems/find-first-and-last-position-of-element-in-sorted-array/) [852. Peak Index in a Mountain Array](https://leetcode.com/problems/peak-index-in-a-mountain-array/) [162. Find Peak Element](https://leetcode.com/problems/find-peak-element/) [1901. Find a Peak Element II](https://leetcode.com/problems/find-a-peak-element-ii/) [153. Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) [33. Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/) [2861. Maximum Number of Alloys](https://leetcode.com/problems/maximum-number-of-alloys/) [410. Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum/) [2616. Minimize the Maximum Difference of Pairs](https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/) [2528. Maximize the Minimum Powered City](https://leetcode.com/problems/maximize-the-minimum-powered-city/) [528. Random Pick with Weight](https://leetcode.com/problems/random-pick-with-weight/) [378. Kth Smallest Element in a Sorted Matrix](https://leetcode.com/problems/kth-smallest-element-in-a-sorted-matrix/) [4. Median of Two Sorted Arrays](https://leetcode.com/problems/median-of-two-sorted-arrays/) [302. Smallest Rectangle Enclosing Black Pixels](https://leetcode.com/problems/smallest-rectangle-enclosing-black-pixels/) [644. Maximum Average Subarray II](https://leetcode.com/problems/maximum-average-subarray-ii/description/) ### 6. Sliding Window [3. Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) [424. Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) [567. Permutation in String](https://leetcode.com/problems/permutation-in-string/) [2799. Count Complete Subarrays in an Array](https://leetcode.com/problems/count-complete-subarrays-in-an-array/) [2962. Count Subarrays Where Max Element Appears at Least K Times](https://leetcode.com/problems/count-subarrays-where-max-element-appears-at-least-k-times/) [713. Subarray Product Less Than K](https://leetcode.com/problems/subarray-product-less-than-k/) [1248. Count Number of Nice Subarrays](https://leetcode.com/problems/count-number-of-nice-subarrays/) [1838. Frequency of the Most Frequent Element](https://leetcode.com/problems/frequency-of-the-most-frequent-element/) [1888. Minimum Number of Flips to Make the Binary String Alternating](https://leetcode.com/problems/minimum-number-of-flips-to-make-the-binary-string-alternating/) [76. Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) [930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/) [992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/) [2968. Apply Operations to Maximize Frequency Score](https://leetcode.com/problems/apply-operations-to-maximize-frequency-score/) ### 7. Backtracking [78. Subsets](https://leetcode.com/problems/subsets/) [90. Subsets II](https://leetcode.com/problems/subsets-ii/) [46. Permutations](https://leetcode.com/problems/permutations/) [47. Permutations II](https://leetcode.com/problems/permutations-ii/) [77. Combinations](https://leetcode.com/problems/combinations/) [39. Combination Sum](https://leetcode.com/problems/combination-sum/) [40. Combination Sum II](https://leetcode.com/problems/combination-sum-ii/) [267. Palindrome Permutation II](https://leetcode.com/problems/palindrome-permutation-ii/) [2928. Distribute Candies Among Children I](https://leetcode.com/problems/distribute-candies-among-children-i/) [51. N-Queens](https://leetcode.com/problems/n-queens/) [679. 24 Game](https://leetcode.com/problems/24-game/) [282. Expression Add Operators](https://leetcode.com/problems/expression-add-operators/) ### 8. Stack [856. Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/) [1209. Remove All Adjacent Duplicates in String II](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string-ii/) [394. Decode String](https://leetcode.com/problems/decode-string/) [1717. Maximum Score From Removing Substrings](https://leetcode.com/problems/maximum-score-from-removing-substrings/) [2197. Replace Non-Coprime Numbers in Array](https://leetcode.com/problems/replace-non-coprime-numbers-in-array/) [32. Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) [895. Maximum Frequency Stack](https://leetcode.com/problems/maximum-frequency-stack/) [772. Basic Calculator III](https://leetcode.com/problems/basic-calculator-iii/) ### 9. Heap (priority_queue) [215. Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/) [373. Find K Pairs with Smallest Sums](https://leetcode.com/problems/find-k-pairs-with-smallest-sums/) [778. Swim in Rising Water](https://leetcode.com/problems/swim-in-rising-water/) [407. Trapping Rain Water II](https://leetcode.com/problems/trapping-rain-water-ii/) [2402. Meeting Rooms III](https://leetcode.com/problems/meeting-rooms-iii/) [295. Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/) [1439. Find the Kth Smallest Sum of a Matrix With Sorted Rows](https://leetcode.com/problems/find-the-kth-smallest-sum-of-a-matrix-with-sorted-rows/) ### 10. Red-Black Tree (multiset, multimap) [480. Sliding Window Median](https://leetcode.com/problems/sliding-window-median/) [1825. Finding MK Average](https://leetcode.com/problems/finding-mk-average/) [3013. Divide an Array Into Subarrays With Minimum Cost II](https://leetcode.com/problems/divide-an-array-into-subarrays-with-minimum-cost-ii/) ### 11. [Monotonic Stack](https://medium.com/@deserter/monotonic-stack-deque-770fcc94c145) [853. Car Fleet](https://leetcode.com/problems/car-fleet/) [901. Online Stock Span](https://leetcode.com/problems/online-stock-span/) [503. Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii/) [1673. Find the Most Competitive Subsequence](https://leetcode.com/problems/find-the-most-competitive-subsequence/) [962. Maximum Width Ramp](https://leetcode.com/problems/maximum-width-ramp/) [1130. Minimum Cost Tree From Leaf Values](https://leetcode.com/problems/minimum-cost-tree-from-leaf-values/) [2289. Steps to Make Array Non-decreasing](https://leetcode.com/problems/steps-to-make-array-non-decreasing/) [2866. Beautiful Towers II](https://leetcode.com/problems/beautiful-towers-ii/) [2863. Maximum Length of Semi-Decreasing Subarrays](https://leetcode.com/problems/maximum-length-of-semi-decreasing-subarrays/) [84. Largest Rectangle in Histogram](https://leetcode.com/problems/largest-rectangle-in-histogram/) [907. Sum of Subarray Minimums](https://leetcode.com/problems/sum-of-subarray-minimums/) [1504. Count Submatrices With All Ones](https://leetcode.com/problems/count-submatrices-with-all-ones/) [2281. Sum of Total Strength of Wizards](https://leetcode.com/problems/sum-of-total-strength-of-wizards/) [402. Remove K Digits](https://leetcode.com/problems/remove-k-digits/) ### 12. Monotonic Queue (deque) [239. Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/) [1696. Jump Game VI](https://leetcode.com/problems/jump-game-vi/) [2919. Minimum Increment Operations to Make Array Beautiful](https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful/) [2944. Minimum Number of Coins for Fruits](https://leetcode.com/problems/minimum-number-of-coins-for-fruits/) [1425. Constrained Subsequence Sum](https://leetcode.com/problems/constrained-subsequence-sum/) [862. Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/) [2398. Maximum Number of Robots Within Budget](https://leetcode.com/problems/maximum-number-of-robots-within-budget/) ### 13. [Graphs](https://leetcode.cn/circle/discuss/01LUak/) #### 13.1. Breadth First Search [994. Rotting Oranges](https://leetcode.com/problems/rotting-oranges/) [1129. Shortest Path with Alternating Colors](https://leetcode.com/problems/shortest-path-with-alternating-colors/) [752. Open the Lock](https://leetcode.com/problems/open-the-lock/) [279. Perfect Squares](https://leetcode.com/problems/perfect-squares/) [365. Water and Jug Problem](https://leetcode.com/problems/water-and-jug-problem/) [127. Word Ladder](https://leetcode.com/problems/word-ladder/) [126. Word Ladder II](https://leetcode.com/problems/word-ladder-ii/) [1345. Jump Game IV](https://leetcode.com/problems/jump-game-iv/) [1871. Jump Game VII](https://leetcode.com/problems/jump-game-vii/) #### 13.2. Depth First Search [1254. Number of Closed Islands](https://leetcode.com/problems/number-of-closed-islands/) [489. Robot Room Cleaner](https://leetcode.com/problems/robot-room-cleaner/) [2385. Amount of Time for Binary Tree to Be Infected](https://leetcode.com/problems/amount-of-time-for-binary-tree-to-be-infected/) [797. All Paths From Source to Target](https://leetcode.com/problems/all-paths-from-source-to-target/) [2608. Shortest Cycle in a Graph](https://leetcode.com/problems/shortest-cycle-in-a-graph/) [2360. Longest Cycle in a Graph](https://leetcode.com/problems/longest-cycle-in-a-graph/) [2876. Count Visited Nodes in a Directed Graph](https://leetcode.com/problems/count-visited-nodes-in-a-directed-graph/) #### 13.3. Linked List [160. Intersection of Two Linked Lists](https://leetcode.com/problems/intersection-of-two-linked-lists/) [142. Linked List Cycle II](https://leetcode.com/problems/linked-list-cycle-ii/) [19. Remove Nth Node From End of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) [138. Copy List with Random Pointer](https://leetcode.com/problems/copy-list-with-random-pointer/) [817. Linked List Components](https://leetcode.com/problems/linked-list-components/) [1171. Remove Zero Sum Consecutive Nodes from Linked List](https://leetcode.com/problems/remove-zero-sum-consecutive-nodes-from-linked-list/) [148. Sort List](https://leetcode.com/problems/sort-list/) [25. Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/) [23. Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) [146. LRU Cache](https://leetcode.com/problems/lru-cache/) [460. LFU Cache](https://leetcode.com/problems/lfu-cache/) #### 13.4. Binary Tree [144. Binary Tree Preorder Traversal](https://leetcode.com/problems/binary-tree-preorder-traversal/) [94. Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) [145. Binary Tree Postorder Traversal](https://leetcode.com/problems/binary-tree-postorder-traversal/) [102. Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/) [314. Binary Tree Vertical Order Traversal](https://leetcode.com/problems/binary-tree-vertical-order-traversal/) [199. Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/) [543. Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/) [236. Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/) [1650. Lowest Common Ancestor of a Binary Tree III](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/) [1676. Lowest Common Ancestor of a Binary Tree IV](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iv/) [1740. Find Distance in a Binary Tree](https://leetcode.com/problems/find-distance-in-a-binary-tree/) [222. Count Complete Tree Nodes](https://leetcode.com/problems/count-complete-tree-nodes/) [572. Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/) [297. Serialize and Deserialize Binary Tree](https://leetcode.com/problems/serialize-and-deserialize-binary-tree/) [2458. Height of Binary Tree After Subtree Removal Queries](https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/) #### 13.5. Binary Search Tree [230. Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/) [235. Lowest Common Ancestor of a Binary Search Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/) [108. Convert Sorted Array to Binary Search Tree](https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/) #### 13.6. N-Ary Tree [589. N-ary Tree Preorder Traversal](https://leetcode.com/problems/n-ary-tree-preorder-traversal/) [590. N-ary Tree Postorder Traversal](https://leetcode.com/problems/n-ary-tree-postorder-traversal/) [429. N-ary Tree Level Order Traversal](https://leetcode.com/problems/n-ary-tree-level-order-traversal/) [1522. Diameter of N-Ary Tree](https://leetcode.com/problems/diameter-of-n-ary-tree/) #### 13.7. [Binary Lifting](https://leetcode.com/discuss/study-guide/4299594/Binary-Lifting-Technique/) [1483. Kth Ancestor of a Tree Node](https://leetcode.com/problems/kth-ancestor-of-a-tree-node/) [2836. Maximize Value of Function in a Ball Passing Game](https://leetcode.com/problems/maximize-value-of-function-in-a-ball-passing-game/) [2846. Minimum Edge Weight Equilibrium Queries in a Tree](https://leetcode.com/problems/minimum-edge-weight-equilibrium-queries-in-a-tree/) #### 13.8. Disjoint Set Union-Find [200. Number of Islands](https://leetcode.com/problems/number-of-islands/) [990. Satisfiability of Equality Equations](https://leetcode.com/problems/satisfiability-of-equality-equations/) [399. Evaluate Division](https://leetcode.com/problems/evaluate-division/) [1202. Smallest String With Swaps](https://leetcode.com/problems/smallest-string-with-swaps/) [947. Most Stones Removed with Same Row or Column](https://leetcode.com/problems/most-stones-removed-with-same-row-or-column/) #### 13.9. Topological sorting ##### Kahn's Algorithm [210. Course Schedule II](https://leetcode.com/problems/course-schedule-ii/) [1136. Parallel Courses](https://leetcode.com/problems/parallel-courses/) [310. Minimum Height Trees](https://leetcode.com/problems/minimum-height-trees/) [269. Alien Dictionary](https://leetcode.com/problems/alien-dictionary/) [2204. Distance to a Cycle in Undirected Graph](https://leetcode.com/problems/distance-to-a-cycle-in-undirected-graph/) [1203. Sort Items by Groups Respecting Dependencies](https://leetcode.com/problems/sort-items-by-groups-respecting-dependencies/) [1591. Strange Printer II](https://leetcode.com/problems/strange-printer-ii/) #### 13.10. Trie (Prefix Tree) [208. Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/) [212. Word Search II](https://leetcode.com/problems/word-search-ii/) [421. Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) [472. Concatenated Words](https://leetcode.com/problems/concatenated-words/) [642. Design Search Autocomplete System](https://leetcode.com/problems/design-search-autocomplete-system/) [3045. Count Prefix and Suffix Pairs II](https://leetcode.com/problems/count-prefix-and-suffix-pairs-ii/) #### 13.11. Minimum Spanning Tree ##### Kruskal's Algorithm [1489. Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree](https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/) [1168. Optimize Water Distribution in a Village](https://leetcode.com/problems/optimize-water-distribution-in-a-village/) ##### Prim’s Algorithm [1584. Min Cost to Connect All Points](https://leetcode.com/problems/min-cost-to-connect-all-points/) #### 13.12. Segment Tree & Binary Indexed Tree(Fenwick Tree) *Non-STL C++ Lib for Ordered Set: [GNU PBDS](https://medium.com/nybles/policy-based-data-structure-491ac62ddeaa) [307. Range Sum Query - Mutable](https://leetcode.com/problems/range-sum-query-mutable/) [308. Range Sum Query 2D - Mutable](https://leetcode.com/problems/range-sum-query-2d-mutable/) [315. Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) [3072. Distribute Elements Into Two Arrays II](https://leetcode.com/problems/distribute-elements-into-two-arrays-ii/) [3161. Block Placement Queries](https://leetcode.com/problems/block-placement-queries/) [850. Rectangle Area II](https://leetcode.com/problems/falling-squares/) [2407. Longest Increasing Subsequence II](https://leetcode.com/problems/longest-increasing-subsequence-ii/) #### 13.13. Shortest Path ##### Bellman-Ford Algorithm (Shortest Path Faster Algorithm (SPFA)) [787. Cheapest Flights Within K Stops](https://leetcode.com/problems/cheapest-flights-within-k-stops/) ##### Dijkstra's Algorithm [743. Network Delay Time](https://leetcode.com/problems/network-delay-time/) [3112. Minimum Time to Visit Disappearing Nodes](https://leetcode.com/problems/minimum-time-to-visit-disappearing-nodes/) [1976. Number of Ways to Arrive at Destination](https://leetcode.com/problems/number-of-ways-to-arrive-at-destination/) [2045. Second Minimum Time to Reach Destination](https://leetcode.com/problems/second-minimum-time-to-reach-destination/) [3123. Find Edges in Shortest Paths](https://leetcode.com/problems/find-edges-in-shortest-paths/) [2092. Find All People With Secret](https://leetcode.com/problems/find-all-people-with-secret/) [514. Freedom Trail](https://leetcode.com/problems/freedom-trail/) [2203. Minimum Weighted Subgraph With the Required Paths](https://leetcode.com/problems/minimum-weighted-subgraph-with-the-required-paths/) ##### Floyd Warshall Algorithm [2976. Minimum Cost to Convert String I](https://leetcode.com/problems/minimum-cost-to-convert-string-i/) [1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance](https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/) [2959. Number of Possible Sets of Closing Branches](https://leetcode.com/problems/number-of-possible-sets-of-closing-branches/) #### 13.14. Eulerian Circuit / Path ##### Hierholzer's Algorithm [332. Reconstruct Itinerary](https://leetcode.com/problems/reconstruct-itinerary/) [2097. Valid Arrangement of Pairs](https://leetcode.com/problems/valid-arrangement-of-pairs/) #### 13.15. Hamiltonian Circuit / Path [753. Cracking the Safe](https://leetcode.com/problems/cracking-the-safe/) #### 13.16. Connected Components ##### Articulation Point [1568. Minimum Number of Days to Disconnect Island](https://leetcode.com/problems/minimum-number-of-days-to-disconnect-island/) ##### Bridge [1192. Critical Connections in a Network](https://leetcode.com/problems/critical-connections-in-a-network/) ##### Strongly Connected Component [2127. Maximum Employees to Be Invited to a Meeting](https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting/) #### 13.17. Bipartite Graph [886. Possible Bipartition](https://leetcode.com/problems/possible-bipartition/) [1820. Maximum Number Of Accepted Invitations](https://leetcode.com/problems/maximum-number-of-accepted-invitations/) [2123. Minimum Operations to Remove Adjacent Ones in Matrix](https://leetcode.com/problems/minimum-operations-to-remove-adjacent-ones-in-matrix/) ### [14. Dynamic Programing](https://leetcode.cn/circle/discuss/tXLS3i/) #### 14.1. One-Dimensional DP [198. House Robber](https://leetcode.com/problems/house-robber/) [213. House Robber II](https://leetcode.com/problems/house-robber-ii/) [3186. Maximum Total Damage With Spell Casting](https://leetcode.com/problems/maximum-total-damage-with-spell-casting/) [983. Minimum Cost For Tickets](https://leetcode.com/problems/minimum-cost-for-tickets/) [2008. Maximum Earnings From Taxi](https://leetcode.com/problems/maximum-earnings-from-taxi/) [2830. Maximize the Profit as the Salesman](https://leetcode.com/problems/maximize-the-profit-as-the-salesman/) [300. Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) [2370. Longest Ideal Subsequence](https://leetcode.com/problems/longest-ideal-subsequence/) [1027. Longest Arithmetic Subsequence](https://leetcode.com/problems/longest-arithmetic-subsequence/) [873. Length of Longest Fibonacci Subsequence](https://leetcode.com/problems/length-of-longest-fibonacci-subsequence/) [673. Number of Longest Increasing Subsequence](https://leetcode.com/problems/number-of-longest-increasing-subsequence/) [1626. Best Team With No Conflicts](https://leetcode.com/problems/best-team-with-no-conflicts/) [354. Russian Doll Envelopes](https://leetcode.com/problems/russian-doll-envelopes/) #### 14.2. Knapsack DP ##### 14.2.1 One-Dimensional [322. Coin Change](https://leetcode.com/problems/coin-change/) [518. Coin Change II](https://leetcode.com/problems/coin-change-ii/) [377. Combination Sum IV](https://leetcode.com/problems/combination-sum-iv/?envType=study-plan-v2&envId=dynamic-programming) [416. Partition Equal Subset Sum](https://leetcode.com/problems/partition-equal-subset-sum/) [1155. Number of Dice Rolls With Target Sum](https://leetcode.com/problems/number-of-dice-rolls-with-target-sum/) [2585. Number of Ways to Earn Points](https://leetcode.com/problems/number-of-ways-to-earn-points/) [1049. Last Stone Weight II](https://leetcode.com/problems/last-stone-weight-ii/) ##### 14.2.2 Two-Dimensional [474. Ones and Zeroes](https://leetcode.com/problems/ones-and-zeroes/) [879. Profitable Schemes](https://leetcode.com/problems/profitable-schemes/) [3082. Find the Sum of the Power of All Subsequences](https://leetcode.com/problems/find-the-sum-of-the-power-of-all-subsequences/) #### 14.3. Partition DP [2707. Extra Characters in a String](https://leetcode.com/problems/extra-characters-in-a-string/) [2430. Maximum Deletions on a String](https://leetcode.com/problems/maximum-deletions-on-a-string/) [1043. Partition Array for Maximum Sum](https://leetcode.com/problems/partition-array-for-maximum-sum/) [813. Largest Sum of Averages](https://leetcode.com/problems/largest-sum-of-averages/) [1335. Minimum Difficulty of a Job Schedule](https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/) [1278. Palindrome Partitioning III](https://leetcode.com/problems/palindrome-partitioning-iii/) [2547. Minimum Cost to Split an Array](https://leetcode.com/problems/minimum-cost-to-split-an-array/) [1478. Allocate Mailboxes](https://leetcode.com/problems/allocate-mailboxes/) [2218. Maximum Value of K Coins From Piles](https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/?envType=study-plan-v2&envId=dynamic-programming) [3077. Maximum Strength of K Disjoint Subarrays](https://leetcode.com/problems/maximum-strength-of-k-disjoint-subarrays/) #### 14.4. Two-Dimensional DP [5. Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) [516. Longest Palindromic Subsequence](https://leetcode.com/problems/longest-palindromic-subsequence/) [647. Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) [730. Count Different Palindromic Subsequences](https://leetcode.com/problems/count-different-palindromic-subsequences/) [1143. Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/) [72. Edit Distance](https://leetcode.com/problems/edit-distance/?envType=study-plan-v2&envId=dynamic-programming) [10. Regular Expression Matching](https://leetcode.com/problems/regular-expression-matching/) [920. Number of Music Playlists](https://leetcode.com/problems/number-of-music-playlists/) #### 14.5. Multi-Dimensional DP [2930. Number of Strings Which Can Be Rearranged to Contain Substring](https://leetcode.com/problems/number-of-strings-which-can-be-rearranged-to-contain-substring/) [1444. Number of Ways of Cutting a Pizza](https://leetcode.com/problems/number-of-ways-of-cutting-a-pizza/) [741. Cherry Pickup](https://leetcode.com/problems/cherry-pickup/) [87. Scramble String](https://leetcode.com/problems/scramble-string/) #### 14.6. Grid DP [576. Out of Boundary Paths](https://leetcode.com/problems/out-of-boundary-paths/description/) [221. Maximal Square](https://leetcode.com/problems/maximal-square/) [3148. Maximum Difference Score in a Grid](https://leetcode.com/problems/maximum-difference-score-in-a-grid/) [2088. Count Fertile Pyramids in a Land](https://leetcode.com/problems/count-fertile-pyramids-in-a-land/) [790. Domino and Tromino Tiling](https://leetcode.com/problems/domino-and-tromino-tiling/) #### 14.7. Deterministic Finite Automaton (Finite State Machine) DP [121. Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/) [122. Best Time to Buy and Sell Stock II](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/) [714. Best Time to Buy and Sell Stock with Transaction Fee](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-transaction-fee/) [309. Best Time to Buy and Sell Stock with Cooldown](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/) [123. Best Time to Buy and Sell Stock III](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iii/) [188. Best Time to Buy and Sell Stock IV](https://leetcode.com/problems/best-time-to-buy-and-sell-stock-iv/) #### 14.8. Divide and Conquer DP (Catalan Number) [894. All Possible Full Binary Trees](https://leetcode.com/problems/all-possible-full-binary-trees/) [96. Unique Binary Search Trees](https://leetcode.com/problems/unique-binary-search-trees/) [95. Unique Binary Search Trees II](https://leetcode.com/problems/unique-binary-search-trees-ii/) [241. Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/) [312. Burst Balloons](https://leetcode.com/problems/burst-balloons/) [1039. Minimum Score Triangulation of Polygon](https://leetcode.com/problems/minimum-score-triangulation-of-polygon/) [664. Strange Printer](https://leetcode.com/problems/strange-printer/) [1000. Minimum Cost to Merge Stones](https://leetcode.com/problems/minimum-cost-to-merge-stones/) [546. Remove Boxes](https://leetcode.com/problems/remove-boxes/) #### 14.9. Tree DP [2920. Maximum Points After Collecting Coins From All Nodes](https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes/) [834. Sum of Distances in Tree](https://leetcode.com/problems/sum-of-distances-in-tree/) [968. Binary Tree Cameras](https://leetcode.com/problems/binary-tree-cameras/) [1569. Number of Ways to Reorder Array to Get Same BST](https://leetcode.com/problems/number-of-ways-to-reorder-array-to-get-same-bst/) #### 14.10. Digit DP [2719. Count of Integers](https://leetcode.com/problems/count-of-integers/) [2376. Count Special Integers](https://leetcode.com/problems/count-special-integers/) [2999. Count the Number of Powerful Integers](https://leetcode.com/problems/count-the-number-of-powerful-integers/) [233. Number of Digit One](https://leetcode.com/problems/number-of-digit-one/) [1397. Find All Good Strings](https://leetcode.com/problems/find-all-good-strings/) #### 14.11. Bitmask DP [2305. Fair Distribution of Cookies](https://leetcode.com/problems/fair-distribution-of-cookies/) [1879. Minimum XOR Sum of Two Arrays](https://leetcode.com/problems/minimum-xor-sum-of-two-arrays/) [698. Partition to K Equal Sum Subsets](https://leetcode.com/problems/partition-to-k-equal-sum-subsets/) [1986. Minimum Number of Work Sessions to Finish the Tasks](https://leetcode.com/problems/minimum-number-of-work-sessions-to-finish-the-tasks/) [1349. Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam/) [1125. Smallest Sufficient Team](https://leetcode.com/problems/smallest-sufficient-team/) [805. Split Array With Same Average](https://leetcode.com/problems/split-array-with-same-average/) [847. Shortest Path Visiting All Nodes](https://leetcode.com/problems/shortest-path-visiting-all-nodes/) [3149. Find the Minimum Cost Array Permutation](https://leetcode.com/problems/find-the-minimum-cost-array-permutation/) [943. Find the Shortest Superstring](https://leetcode.com/problems/find-the-shortest-superstring/) #### 14.12. Probability DP [808. Soup Servings](https://leetcode.com/problems/soup-servings/) [837. New 21 Game](https://leetcode.com/problems/new-21-game/) #### 14.13. Game DP [877. Stone Game](https://leetcode.com/problems/stone-game/) [1140. Stone Game II](https://leetcode.com/problems/stone-game-ii/) [1406. Stone Game III](https://leetcode.com/problems/stone-game-iii/) ### 15. Greedy #### 15.1. Common [277. Find the Celebrity](https://leetcode.com/problems/find-the-celebrity/) [45. Jump Game II](https://leetcode.com/problems/jump-game-ii/) [2116. Check if a Parentheses String Can Be Valid](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) [991. Broken Calculator](https://leetcode.com/problems/broken-calculator/) [3091. Apply Operations to Make Sum of Array Greater Than or Equal to k](https://leetcode.com/problems/apply-operations-to-make-sum-of-array-greater-than-or-equal-to-k/) [179. Largest Number](https://leetcode.com/problems/largest-number/) [358. Rearrange String k Distance Apart](https://leetcode.com/problems/rearrange-string-k-distance-apart/) ##### Kadane's Algorithm [53. Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) [918. Maximum Sum Circular Subarray](https://leetcode.com/problems/maximum-sum-circular-subarray/) #### 15.2. Greedy with Heap (反悔貪心) [1642. Furthest Building You Can Reach](https://leetcode.com/problems/furthest-building-you-can-reach/) [2599. Make the Prefix Sum Non-negative](https://leetcode.com/problems/make-the-prefix-sum-non-negative/) [630. Course Schedule III](https://leetcode.com/problems/course-schedule-iii/) [871. Minimum Number of Refueling Stops](https://leetcode.com/problems/minimum-number-of-refueling-stops/) [2813. Maximum Elegance of a K-Length Subsequence](https://leetcode.com/problems/maximum-elegance-of-a-k-length-subsequence/) ### 16. [Sweep Line](https://leetcode.com/discuss/study-guide/2166045/line-sweep-algorithms) [253. Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/) [1109. Corporate Flight Bookings](https://leetcode.com/problems/corporate-flight-bookings/) [2237. Count Positions on Street With Required Brightness](https://leetcode.com/problems/count-positions-on-street-with-required-brightness/) [1094. Car Pooling](https://leetcode.com/problems/car-pooling/) [452. Minimum Number of Arrows to Burst Balloons](https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/) [1353. Maximum Number of Events That Can Be Attended](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended/) [2251. Number of Flowers in Full Bloom](https://leetcode.com/problems/number-of-flowers-in-full-bloom/) [1851. Minimum Interval to Include Each Query](https://leetcode.com/problems/minimum-interval-to-include-each-query/) [1326. Minimum Number of Taps to Open to Water a Garden](https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden/) [3009. Maximum Number of Intersections on the Chart](https://leetcode.com/problems/maximum-number-of-intersections-on-the-chart/) [850. Rectangle Area II](https://leetcode.com/problems/rectangle-area-ii/) [218. The Skyline Problem](https://leetcode.com/problems/the-skyline-problem/) ### 17. Intervals [646. Maximum Length of Pair Chain](https://leetcode.com/problems/maximum-length-of-pair-chain/) [435. Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/) [1235. Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/) [56. Merge Intervals](https://leetcode.com/problems/merge-intervals/) [57. Insert Interval](https://leetcode.com/problems/insert-interval/) [1272. Remove Interval](https://leetcode.com/problems/remove-interval/) [1288. Remove Covered Intervals](https://leetcode.com/problems/remove-covered-intervals/) [729. My Calendar I](https://leetcode.com/problems/my-calendar-i/) [731. My Calendar II](https://leetcode.com/problems/my-calendar-ii/) [715. Range Module](https://leetcode.com/problems/range-module/) [759. Employee Free Time](https://leetcode.com/problems/employee-free-time/) ### 18. [Math](https://leetcode.cn/circle/discuss/IYT3ss/) [69. Sqrt(x)](https://leetcode.com/problems/sqrtx/) [50. Pow(x, n)](https://leetcode.com/problems/powx-n/) [2961. Double Modular Exponentiation](https://leetcode.com/problems/double-modular-exponentiation/) [650. 2 Keys Keyboard](https://leetcode.com/problems/2-keys-keyboard/) [1291. Sequential Digits](https://leetcode.com/problems/sequential-digits/) [2929. Distribute Candies Among Children II](https://leetcode.com/problems/distribute-candies-among-children-ii/) [3116. Kth Smallest Amount With Single Denomination Combination](https://leetcode.com/problems/kth-smallest-amount-with-single-denomination-combination/) [2507. Smallest Value After Replacing With Sum of Prime Factors](https://leetcode.com/problems/smallest-value-after-replacing-with-sum-of-prime-factors/) [3138. Minimum Length of Anagram Concatenation](https://leetcode.com/problems/minimum-length-of-anagram-concatenation/) [3164. Find the Number of Good Pairs II](https://leetcode.com/problems/find-the-number-of-good-pairs-ii/) [1862. Sum of Floored Pairs](https://leetcode.com/problems/sum-of-floored-pairs/) [204. Count Primes](https://leetcode.com/problems/count-primes/) [2514. Count Anagrams](https://leetcode.com/problems/count-anagrams/) ### 19. Geometry #### 19.1. Common [3047. Find the Largest Area of Square Inside Two Rectangles](https://leetcode.com/problems/find-the-largest-area-of-square-inside-two-rectangles/) [2013. Detect Squares](https://leetcode.com/problems/detect-squares/) [2101. Detonate the Maximum Bombs](https://leetcode.com/problems/detonate-the-maximum-bombs/) [3027. Find the Number of Ways to Place People II](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-ii/) [1739. Building Boxes](https://leetcode.com/problems/building-boxes/) [1610. Maximum Number of Visible Points](https://leetcode.com/problems/maximum-number-of-visible-points/) [1515. Best Position for a Service Centre](https://leetcode.com/problems/best-position-for-a-service-centre/) #### 19.3. Manhattan / Chebyshev Distance [296. Best Meeting Point](https://leetcode.com/problems/best-meeting-point/) [3102. Minimize Manhattan Distances](https://leetcode.com/problems/minimize-manhattan-distances/) [1131. Maximum of Absolute Value Expression](https://leetcode.com/problems/maximum-of-absolute-value-expression/) #### 19.3. Convex Hull [587. Erect the Fence](https://leetcode.com/problems/erect-the-fence/description/) ### 20. [Bit Manipulation](https://leetcode.cn/circle/discuss/dHn9Vk/) [136. Single Number](https://leetcode.com/problems/single-number/) [191. Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) [338. Counting Bits](https://leetcode.com/problems/counting-bits/) [190. Reverse Bits](https://leetcode.com/problems/reverse-bits/) [268. Missing Number](https://leetcode.com/problems/missing-number/) [645. Set Mismatch](https://leetcode.com/problems/set-mismatch/) [2397. Maximum Rows Covered by Columns](https://leetcode.com/problems/maximum-rows-covered-by-columns/) [201. Bitwise AND of Numbers Range](https://leetcode.com/problems/bitwise-and-of-numbers-range/) [371. Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) [2857. Count Pairs of Points With Distance k](https://leetcode.com/problems/count-pairs-of-points-with-distance-k/) [2939. Maximum Xor Product](https://leetcode.com/problems/maximum-xor-product/) [3022. Minimize OR of Remaining Elements Using Operations](https://leetcode.com/problems/minimize-or-of-remaining-elements-using-operations/) ### 21. Voting [169. Majority Element](https://leetcode.com/problems/majority-element/) [229. Majority Element II](https://leetcode.com/problems/majority-element-ii/) ### 22. Concurrency [1188. Design Bounded Blocking Queue](https://leetcode.com/problems/design-bounded-blocking-queue/) [1242. Web Crawler Multithreaded](https://leetcode.com/problems/web-crawler-multithreaded/)