Problem · Dynamic Programming
Count Bitonic Subsequences
Learn this problemProblem statement
Count non-empty subsequences that strictly increase to an interior peak and then strictly decrease. Both the increasing and decreasing parts must contain at least one step. Return the count modulo 10^9 + 7.
Function
countBitonicSubsequences(arr: int[]) → intExamples
Example 1
arr = [1,2,3,2,1]return = 11Eleven index-distinct subsequences have a strict rise followed by a strict fall.
Example 2
arr = [1,2,3,1]return = 4The valid subsequences are [1,2,1], [1,3,1], [2,3,1], and [1,2,3,1].
Constraints
1 <= arr.length <= 1000001 <= arr[i] <= 200