FastPrepCount Strictly Increasing Subsequences of Length 3
Problems/Count Strictly Increasing Subsequences of Length 3

Count Strictly Increasing Subsequences of Length 3

IBM logoIBM● MediumOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: This question is backed by a real IBM assessment screenshot. The source directly provides the counting rule, modulo, both examples, and constraints, but it does not show a function name or signature. The core task match is about 95%.

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[]) → int

Examples

Example 1

n = 5arr = [1, 2, 3, 4, 1]return = 4

The 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 = 2

The two strictly increasing subsequences are [3, 4, 5] and [1, 4, 5].

Constraints

  • 1 ≤ n ≤ 5000
  • 0 ≤ arr[i] ≤ 10^9

More IBM problems

  • Count Strictly Increasing Contiguous WindowsOA · Seen Nov 2026
  • Total Each Letter's Count in an Encoded StringOA · Seen Nov 2026
  • Count Servers With No Requests in a Time WindowOA · Seen Nov 2026
All IBM interview questionsSee IBM hiring insights
Saved
class Solution {
    public int countIncreasingSubsequences(int n, int[] arr) {
      // write your code here
    }
}
Checking account…