685. Longest Bitonic Subsequence
Given an array arr of n integers, the task is to find the length of the longest bitonic sequence. A sequence is considered bitonic if it is strictly increasing, strictly decreasing, or strictly increases and then strictly decreases.. The sequence does not have to be contiguous.
Example 1:
Input: arr = [5, 1, 4, 2, 3, 6, 8, 7]
Output: 6
Explanation: The longest bitonic sequence is [1, 2, 3, 6, 8, 7] with length 6.
Example 2:
Input: arr = [10, 20, 30, 40, 50, 40, 30, 20]
Output: 8
Explanation: The entire array is bitonic, increasing up to 50 and then decreasing.
Now Your Turn!
Pick the correct output for the given inputInput: arr = [12, 11, 10, 15, 18, 17, 16, 14]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= arr.length <= 103
- -106<= arr[i] <= 106