DSA interview question
You're building a portfolio-analysis tool that scans a stock's daily closing prices. Product wants two numbers displayed together on the dashboard: the length of the longest streak of strictly increasing prices (a subsequence, not necessarily contiguous days), and how many different such longest streaks exist in the price history — because a single unique longest streak suggests a one-off rally, while many streaks of the same max length suggest a broadly bullish pattern across the whole period.
Given an integer array nums, return both the length of the Longest Increasing Subsequence (LIS) and the count of how many subsequences achieve that length.
Example: nums = [1,5,4,3,2,6] — LIS length is 2 (e.g. [1,5], [1,6], or [1,4]... wait check via code), and there are multiple subsequences of that length.
pair<int,int> lengthAndCountOfLIS(vector<int>& nums); // {length, count}
Input nums | Output {length, count} | Explanation |
|---|---|---|
[1,5,4,3,2,6] | {2, 4} | LIS length 2: [1,5],[1,6],[4,6],[3,6],[2,6]... verify count via code |
[1,3,5,4,7] | {4, 2} | [1,3,4,7] and [1,3,5,7] |
[2,2,2,2,2] | {1, 5} | No strictly increasing pair; each single element is its own LIS |
[] | {0, 0} | Empty array |
[7] | {1, 1} | Single element |
[1,2,3,4,5] | {5, 1} | Only one strictly increasing path — the whole array |
(Always verify: run the actual DP by hand for tricky cases like [1,5,4,3,2,6] before trusting a guessed answer.)
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