Three patterns to remember from LIS (Longest Increasing Subsequence):
"Ending at " states let you know exactly what to extend from. This pattern appears in many subsequence problems.
The answer might not be at the last index. Check if you need or .
Picking the locally best option fails when those choices affect future options. DP (dynamic programming) explores all paths. The solution works for . For larger inputs, you need the improvement.