Number of Longest Increasing Subsequence
Problem
Given an integer array nums, let L be the length of its longest strictly increasing subsequence. Return how many distinct subsequences (by index set) of length L are strictly increasing. Two subsequences that pick different indices count separately even if they contain the same values.
numsholds up to a couple thousand integers.- Values can be negative or positive, well within a normal signed integer range.
Examples
nums = [2, 4, 6, 5, 8]→2. The longest length is 4, achieved by2, 4, 6, 8and2, 4, 5, 8.nums = [7, 7, 7, 7, 7]→5. Every increasing subsequence has length 1, and there are five single elements.nums = [2, 3, 5, 4, 6, 5, 8, 3]→3. Length 5 via2,3,5,6,8,2,3,4,6,8, and2,3,4,5,8.
Hints
- Start from the O(n^2) LIS DP where
length[i]is the longest increasing subsequence ending ati. What second quantity would you need per index to count them? - When extending
ifrom an earlierj, there are three cases:jgives a strictly longer result, an equally long one, or a shorter one. What happens to the count in each? - Track
count[i]alongsidelength[i]; on a strictly longer candidate reset the count tocount[j], on a tie addcount[j], then sumcount[i]over indices withlength[i] == max.
Last reviewed 8 September 2026
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.