Problem · Array
Find Length of Longest Bitonic Subarray
Learn this problemProblem statement
A bitonic sequence is a sequence of numbers that first increase (non-decreasing) and then decreases (non-increasing). Given an array of integers, find the length of the longest subarray that is bitonic in nature.
Function
findLengthOfLongestBitonicSubarray(arr: int[]) → intExamples
Example 1
arr = [10, 8, 9, 15, 12, 6, 7]return = 5[8,9,15,12,6] is the longest bitonic subarray. Return its length, 5.
Example 2
arr = [5, 1, 2, 1, 4, 5]return = 3[1,2,1]is the longest bitonic subarray. Note that the subarray[1,4,5]is also bitonic in nature and has the same length. It is non-decreasing through[1,4,5]and the non-increasing portion is[5].
Example 3
arr = [9, 7, 6, 2, 1]return = 5The non-decreasing subarray is[9]. The non-increasing subarray is the entire array. The entire array has 5 elements.
Constraints
1 ≤ n ≤ 10^51 ≤ arr[i] ≤ 10^9
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · Seen Jul 2026
- Count Strictly Increasing Subsequences of Length 3OA · Seen Jul 2026
- Maximum Requests in a Time WindowOA · Seen Jul 2026
- Query Type Frequency WindowOA · Seen Jul 2026
- Minimum Number of Non-Empty Disjoint SegmentsOA · Seen Jul 2026
- Spam Text ClassificationOA · Seen Jul 2026
- Count Ideal NumbersOA · Seen Jun 2026