Problem · Array
Count Strictly Increasing Subsequences of Length 3
Learn this problemProblem statement
Given an integer array arr of length n, return the number of strictly increasing subsequences of length 3, modulo 10^9 + 7.
A subsequence is obtained by deleting zero or more elements without changing the order of the remaining elements. A length-3 subsequence is strictly increasing when its indices satisfy i < j < k and its values satisfy arr[i] < arr[j] < arr[k].
Function
countIncreasingSubsequences(n: int, arr: int[]) → intExamples
Example 1
n = 5arr = [1, 2, 3, 4, 1]return = 4The strictly increasing subsequences are [1, 2, 3], [1, 2, 4], [1, 3, 4], and [2, 3, 4]. Therefore, the answer is 4.
Example 2
n = 4arr = [3, 1, 4, 5]return = 2The two strictly increasing subsequences are [3, 4, 5] and [1, 4, 5].
Constraints
1 ≤ n ≤ 50000 ≤ arr[i] ≤ 10^9
More IBM problems
- Parent Process NumberOA · Seen Jul 2026
- Request Retry CountOA · 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
- Count Descending SubarraysOA · Seen Apr 2026