Number of Longest Increasing Subsequence

Medium Topics Company Tags

Return the number of strictly increasing subsequences of nums whose length is as large as possible. A subsequence preserves the original order while possibly skipping entries. Different choices of indices count separately. The answer is guaranteed to fit in a signed 32-bit integer.

Example 1:

Input: nums = [1,2,2,3]

Output: 2

Explanation: The longest length is 3. Choose 1, either occurrence of 2, and 3, giving two different choices of indices.

Example 2:

Input: nums = [4,3,2,1]

Output: 4

Explanation: No two entries in their original order are strictly increasing. The longest length is 1, and each of the four indices gives one subsequence.

Example 3:

Input: nums = [-3,-2,-1]

Output: 1

Explanation: The whole array is strictly increasing, so its length-3 subsequence is the unique longest one.

Constraints:

  • 1 <= nums.length <= 2000
  • -1000000 <= nums[i] <= 1000000
  • The answer fits in a signed 32-bit integer.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.