Overview
A bitonic subsequence goes strictly up and then strictly down. We can find this by combining two Longest Increasing Subsequences (LIS).
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Find the longest subsequence that first increases, then decreases.
A bitonic subsequence goes strictly up and then strictly down. We can find this by combining two Longest Increasing Subsequences (LIS).
Compute `lis[i]`: the length of the longest increasing subsequence ending at index i.
Compute `lds[i]`: the length of the longest decreasing subsequence starting at index i (which is an LIS from right to left).
For any element at index `i`, it can be the "peak" of a bitonic subsequence. The max length with `i` as the peak is `lis[i] + lds[i] - 1`.