LC 3797 - Count Routes to Climb a Rectangular Grid

Approach This is a DP like problem, and I find that we can think that when we want to calculate ans[i][j] on row i from row i-1, we just aggregate the previous row’s ans within the l2 distance of d and we get the answer. But the problem stats that we can jump in the same row in range d, so I tried to buffer the row i-1 aggregated results to jump, and then try to sum up all the jump within distance d. Originally I think that for the index j itself we need to count twice, since we can jump from upper row, or jump from upper row and jump to itself again. However, from the testcase it seems that jump to itself is invalid. Under this circumstance we just add up all the jumps within range d and we got the answer for row i. ...

January 3, 2026 · 4 min

LC 3796 - Find Maximum Value in a Constrained Sequence

Approach This seems like there is a greedy approach. I think that we can represent by a range. If index i is constraint to be smaller than 2, its range is [0, 2]. And if its difference to the next point is smaller than 3, the range for next point is [-3, 5], and we can keep propagate to the right side. Later I found that the number would be positive, so actually we don’t need to care about the negative part, just calculate the largest part. ...

January 3, 2026 · 2 min

LC 3795 - Minimum Subarray Length With Distinct Sum At Least K

Approach This is quite easy to see that is a two pointer type of problem. One difficult part is that for the boundary condition, such as one elemenet only may need some carefull handling (I get WA on that). Also, the sum should remove duplicates so we need to store the count for each variable with a hashmap. Add when there is no this element in the range yet, and remove if this is the last one in the range! (also get 1 WA on this…) ...

January 3, 2026 · 1 min

LC 3794 - Reverse String Prefix

Approach This is really simple, just use the reverse() function. Time complexity is O(N), and no extra space complexity. Code class Solution { public: string reversePrefix(string s, int k) { reverse(s.begin(), s.begin()+k); return s; } };

January 3, 2026 · 1 min