Longest Bitonic Subsequence - Problem
A bitonic subsequence is a subsequence that first strictly increases and then strictly decreases. Given an array of integers, find the length of the longest bitonic subsequence.
A subsequence is derived from the original array by deleting some or no elements without changing the order of the remaining elements.
Note: A purely increasing or purely decreasing subsequence is also considered bitonic.
Input & Output
Example 1 — Standard Bitonic
$
Input:
nums = [1,11,2,10,4,5,2,1]
›
Output:
6
💡 Note:
The longest bitonic subsequence is [1,2,10,5,2,1] or [1,4,5,2,1]. Both have length 6 - they increase to a peak then decrease.
Example 2 — Pure Increasing
$
Input:
nums = [1,2,3,4,5]
›
Output:
5
💡 Note:
The array is strictly increasing. A purely increasing sequence is also considered bitonic, so the answer is 5.
Example 3 — Pure Decreasing
$
Input:
nums = [5,4,3,2,1]
›
Output:
5
💡 Note:
The array is strictly decreasing. A purely decreasing sequence is also considered bitonic, so the answer is 5.
Constraints
- 1 ≤ nums.length ≤ 1000
- -106 ≤ nums[i] ≤ 106
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code