AlgoFrames

Number of longest increasing subsequences

Standard · Write code · about 20 min

Given nums, return how many longest strictly increasing subsequences it has. Two subsequences differ when they use different indices, even if their values are equal.

Example 1

Input:

[[1,3,5,4,7]]

Output:

2

The two runs are 1, 3, 5, 7 and 1, 3, 4, 7.

Example 2

Input:

[[2,2,2,2,2]]

Output:

5

Every single 2 is a longest run of length 1.

Constraints

  • 1 ≤ nums.length ≤ 2000
  • −10⁶ ≤ nums[i] ≤ 10⁶
  • The answer fits in a 32-bit integer.

Learn the idea first: Longest increasing subsequence; the n log n version, a visual lesson.

More Longest increasing subsequence; the n log n version problems