Greedy

Ling Shen Problem List

300. Longest Increasing Subsequence

Ling Shen Video

Define g[i] as the minimum end element of an increasing subsequence of length i+1.

Proof by contradiction: g is a strictly increasing array.

659. Split Array into Consecutive Subsequences

tail[i] is used to represent the number of subsequences ending with i. This way, when i+1 is encountered, it can be placed.

If it cannot be placed, open a new sequence and check if cnt[i+1]>0 and cnt[i+2]>2. If not satisfied, return False.

2422. Convert Array to Palindrome by Merging Operations

Try to keep the left pointer and right pointer pointing to the same value. If one side is smaller, try to merge that side.

When l==r in the end, the array has only 1 number, which is a palindrome.