Google | Onsite | Count Increasing Subsequences
13558
May 30, 2020
May 31, 2020

Given an array arr of size n. Find the number of triples (i, j, k) where:

  1. i < j < k
  2. arr[i] < arr[j] < arr[k]

Example 1:

Input: arr = [1, 2, 3, 4, 5]
Output: 10
Explanation:
1. 1 2 3
2. 1 2 4
3. 1 2 5
4. 1 3 4
5. 1 3 5
6. 1 4 5
7. 2 3 4
8. 2 3 5
9. 2 4 5
10. 3 4 5

Example 2:

Input: arr = [1, 2, 3, 5, 4]
Output: 7

Example 3:

Input: arr = [5, 4, 3, 2, 1]
Output: 0

Follow-up:
Count number of increasing subsequences in the array arr of size k.

Example 1:

Input: arr = [1, 2, 3, 4, 5], k = 4
Output: 5
Explanation:
1. 1 2 3 4
2. 1 2 3 5
3. 1 2 4 5
4. 1 3 4 5
5. 2 3 4 5
Comments (27)