DSA interview question
You're building an analytics feature for a stock-tracking app. Users want to know not just the length of the longest streak of strictly increasing prices in their price history, but how many distinct such longest streaks exist — because if there are many, the trend is "robust" (many paths show growth), and if there's only one, it might be a fragile/coincidental pattern worth flagging differently in the UI.
Given an integer array nums, return the number of longest strictly increasing subsequences (not the LIS itself, just the count of how many subsequences achieve that maximum length).
Example: nums = [1,3,5,4,7] — the longest increasing subsequences have length 3: [1,3,5,7]... wait, that's length 4. Let's verify: [1,3,4,7] and [1,3,5,7] are both length 4. So the answer is 2.
int findNumberOfLIS(vector<int>& nums);
Input nums | Output | Explanation |
|---|---|---|
[1,3,5,4,7] | 2 | [1,3,4,7] and [1,3,5,7] both have length 4 |
[2,2,2,2,2] | 5 | No increasing subsequence longer than length 1; each single element counts |
[1,2,4,3,5,4,7,2] | 3 | Multiple length-5 increasing subsequences exist — verify via dry run |
[] | 0 | Empty array — no subsequences exist |
[7] | 1 | Single element — one subsequence of length 1 |
[1,2,3,4,5] | 1 | Only one strictly increasing path (the whole array) |
(Always verify: are duplicates and single-element arrays handled correctly before coding.)
nums? (If large, e.g. 1e5, signals need for O(n log n) approach instead of O(n²).)On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.
Book a free mock interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in