Number of Longest Increasing Subsequence
MediumDynamic Programming1d dp
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given an integer array nums, return how many strictly increasing subsequences have the maximum possible length.
Two subsequences are different if they use a different set of indices, even when their values are identical. The inputs are chosen so the answer fits in a 32-bit signed integer.
Examples
Input: nums = [1,3,5,4,7]
Output: 2
The longest length is 4: [1,3,4,7] and [1,3,5,7].
Input: nums = [2,2,2,2,2]
Output: 5
The longest length is 1, and each of the 5 indices forms one.
Constraints
- 1 <= nums.length <= 2000
- -10^6 <= nums[i] <= 10^6
- The answer fits in a 32-bit signed integer
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.