Longest Increasing Subsequence II
HardLeetCodeSegment Tree & Fenwick Tree
Approach hintTry it first, then revealHide
Let best[v] be the longest valid subsequence ending with value v. Scanning left to right, best[x] = 1 + max(best[x-k..x-1]), a range-maximum query with point updates on a segment tree indexed by value.