Longest Bitonic Subsequence
Explore the concept of the longest bitonic subsequence, which includes sequences that increase then decrease, only increase, or only decrease. This lesson guides you through naive recursive methods and improved dynamic programming techniques, including top-down memoization and bottom-up tabulation, to efficiently solve this problem in coding interviews.
Statement
Suppose you are given an array, nums, containing positive integers. You need to find the length of the longest bitonic subsequence in this array. A bitonic subsequence can be of the following three types:
-
It can consist of numbers that are first increasing and then decreasing. For example, .
-
It can consist of numbers that are only increasing (where the decreasing part at the end is empty). For example, .
-
It can consist of numbers that are only decreasing (where the increasing part at the start is empty). For example, .
Let’s say you have the following array:
The longest bitonic subsequence from this array is , and the length of this subsequence is .
Constraints:
-
nums.length nums[i]