---
# System prepended metadata

title: Leetcode刷題學習筆記 -- lee215推薦題庫
tags: [刷題, leetcode]

---

lee215在leetcode論壇上，有關題目的[post](https://leetcode.com/discuss/feedback/4518909/happy-new-year-2024)。

## Prefix Problems

| Problems | 心得 |
| -------- | -------- |
| [2281. Sum of Total Strength of Wizards](https://leetcode.com/problems/sum-of-total-strength-of-wizards/description/)     |      |
| [1074. Number of Submatrices That Sum to Target](https://leetcode.com/problems/number-of-submatrices-that-sum-to-target/description/) |怎麼利用prefix sum把$O(N^4)$變成$O(N^3)$。[解法](https://github.com/meyr/leetcode/blob/main/PrefixSum/1074.%20Number%20of%20Submatrices%20That%20Sum%20to%20Target/solution.cpp) |
|[974. Subarray Sums Divisible by K](https://leetcode.com/problems/subarray-sums-divisible-by-k/description/) |怎麼處理prefix sum 為負的情況?[解法](https://github.com/meyr/leetcode/blob/main/PrefixSum/974.%20Subarray%20Sums%20Divisible%20by%20K/solution.cpp) |

+ Prefix Sum的問題都必須注意，使用hash table必須有 sum = 0這個element。
```cpp=
unordered_map<int, int> m{{0, 1}};
```

## Sliding Window Problems

| Problems | 心得 |
| -------- | -------- |
| [2958. Length of Longest Subarray With at Most K Frequency](https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency/description/)|使用unordered_map<int, int>來統計數字出現的次數 |
| [2831. Find the Longest Equal Subarray](https://leetcode.com/problems/find-the-longest-equal-subarray/description/)| |
| [2799. Count Complete Subarrays in an Array](https://leetcode.com/problems/count-complete-subarrays-in-an-array/description/)|滿足條件後，計算subarray的方法</br> ans += nums.size() - right; |
| [2779. Maximum Beauty of an Array After Applying Operation](https://leetcode.com/problems/maximum-beauty-of-an-array-after-applying-operation/description/)| |
| [930. Binary Subarrays With Sum](https://leetcode.com/problems/binary-subarrays-with-sum/description/)|可以用prefix sum來解</br>使用slinding window就必須要用 atMost(goal) - atMost(goal - 1) |
| [992. Subarrays with K Different Integers](https://leetcode.com/problems/subarrays-with-k-different-integers/description/)| |
| [904. Fruit Into Baskets](https://leetcode.com/problems/fruit-into-baskets/description/)| |
| [862. Shortest Subarray with Sum at Least K](https://leetcode.com/problems/shortest-subarray-with-sum-at-least-k/description/)| |
| [424. Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/description/)| |
| [209. Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/description/)    |使用slinding window來追蹤sum的大小 |

## Stack Problems

| Problems | 心得 |
| -------- | -------- |
| [2735. Collecting Chocolates](https://leetcode.com/problems/collecting-chocolates/description/)| |
| [2594. Minimum Time to Repair Cars](https://leetcode.com/problems/minimum-time-to-repair-cars/description/)| |
|[2454. Next Greater Element IV](https://leetcode.com/problems/next-greater-element-iv/description/)| |
| [901. Online Stock Span](https://leetcode.com/problems/online-stock-span/description/)| |
| [856. Score of Parentheses](https://leetcode.com/problems/score-of-parentheses/description/)| |
|[503. Next Greater Element II](https://leetcode.com/problems/next-greater-element-ii/description/) |把array循環兩次|

## Mono Stack Problem

| Problems | 心得 |
| -------- | -------- |
|[2866. Beautiful Towers II](https://leetcode.com/problems/beautiful-towers-ii/description/) | |
|[2454. Next Greater Element IV](https://leetcode.com/problems/next-greater-element-iv/description/) | |
| [2398. Maximum Number of Robots Within Budget](https://leetcode.com/problems/maximum-number-of-robots-within-budget/description/)| |

## Binary Search Problems
| Problems | 心得 |
| -------- | -------- |
|[2616. Minimize the Maximum Difference of Pairs](https://leetcode.com/problems/minimize-the-maximum-difference-of-pairs/description/) | |
| [2560. House Robber IV](https://leetcode.com/problems/house-robber-iv/description/)| |
| [2226. Maximum Candies Allocated to K Children](https://leetcode.com/problems/maximum-candies-allocated-to-k-children/description/)|使用可以分出最大數的堆數 |
| [875. Koko Eating Bananas](https://leetcode.com/problems/koko-eating-bananas/description/)|使用binary search找出答案 |
|[774. Minimize Max Distance to Gas Station](https://leetcode.com/problems/minimize-max-distance-to-gas-station/description/) | |
|[410. Split Array Largest Sum](https://leetcode.com/problems/split-array-largest-sum/description/) | |

## DP problems

| Problems | 心得 |
| -------- | -------- |
|[2920. Maximum Points After Collecting Coins From All Nodes](https://leetcode.com/problems/maximum-points-after-collecting-coins-from-all-nodes/description/)||
|[2919. Minimum Increment Operations to Make Array Beautiful](https://leetcode.com/problems/minimum-increment-operations-to-make-array-beautiful/description/)| |
|[2896. Apply Operations to Make Two Strings Equal](https://leetcode.com/problems/apply-operations-to-make-two-strings-equal/description/) | |
|[2830. Maximize the Profit as the Salesman](https://leetcode.com/problems/maximize-the-profit-as-the-salesman/description/) | |
| [2008. Maximum Earnings From Taxi](https://leetcode.com/problems/maximum-earnings-from-taxi/description/)| |
|[1751. Maximum Number of Events That Can Be Attended II](https://leetcode.com/problems/maximum-number-of-events-that-can-be-attended-ii/description/) | |
| [1235. Maximum Profit in Job Scheduling](https://leetcode.com/problems/maximum-profit-in-job-scheduling/description/)| |