DSA interview question
You're working on a stock analytics dashboard. A product manager wants a feature that highlights the longest streak of days where a stock's closing price could be picked (not necessarily consecutive days) such that the prices strictly increase — this helps visualize the "best possible uptrend" a trader missed. Given an array of daily closing prices nums, you need to return the length of the longest strictly increasing subsequence (LIS).
Note: it's a subsequence, not a subarray — elements don't need to be contiguous, just in relative order.
int lengthOfLIS(vector<int>& nums);
Input nums | Output | Explanation |
|---|---|---|
[10,9,2,5,3,7,101,18] | 4 | LIS is [2,3,7,101] or [2,3,7,18] |
[0,1,0,3,2,3] | 4 | LIS is [0,1,2,3] |
[7,7,7,7,7,7,7] | 1 | Strictly increasing → duplicates don't count |
[1] | 1 | Single element |
[] | 0 | Empty array |
[4,10,4,3,8,9] | 3 | LIS is [4,8,9] |
[1,2,3,4,5] | 5 | Already fully increasing |
(Always clarify "strictly increasing" vs "non-decreasing" before coding — it changes comparator logic.)
n - LIS.< vs <=) in the binary search step.nums? (If n up to 10^5, O(n²) DP will TLE — signals need for O(n log 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