1-D Dynamic Programming Increasing subsequences
528. Number of Longest Increasing Subsequence
You are given an array of integers nums. Find the length of its longest strictly increasing subsequence,
and return how many strictly increasing subsequences have that length.
A subsequence keeps some of the elements, in their original order, and drops the rest. It is strictly increasing when every kept element is bigger than the one kept before it, so two equal values can never both be in it.
Two subsequences are different when they keep different positions, even if their values are the same.
Example 1
Input: nums = [1, 4, 2, 5, 3, 6]
3Explanation: The longest increasing subsequences have length 4. There are three of them: 1, 4, 5, 6, then 1, 2, 5, 6, then 1, 2, 3, 6.
Example 2
Input: nums = [5, 5, 5]
3Explanation: Equal values cannot both be kept, so the longest length is 1. Each of the three elements alone is one such subsequence.
Example 3
Input: nums = [-7, 10, -7, 0, 10]
2Explanation: The longest length is 3, from -7, 0, 10. Either -7 can start it, and they sit at different positions, so they make two subsequences.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ nums.length ≤ 105-109 ≤ nums[i] ≤ 109- The answer is less than 231.
Clarifying questions
What you would ask an interviewer before writing any code.