DSA interview question
You're extending the earlier stock-analytics dashboard feature. Product no longer just wants the length of the longest streak of increasing prices — they now want the actual list of prices that make up one such longest streak, so it can be highlighted directly on the price chart for the user.
Given an integer array nums, return the actual longest strictly increasing subsequence (any one valid instance if multiple exist), not just its length.
Example: nums = [10,9,2,5,3,7,101,18] — one valid longest increasing subsequence is [2,3,7,101] or [2,3,7,18], both length 4.
vector<int> printLIS(vector<int>& nums);
Input nums | Output (one valid answer) | Explanation |
|---|---|---|
[10,9,2,5,3,7,101,18] | [2,3,7,101] | Length 4; [2,3,7,18] is also valid |
[0,1,0,3,2,3] | [0,1,2,3] | Length 4 |
[7,7,7,7,7] | [7] | No strictly increasing pair — any single element |
[] | [] | Empty array |
[5] | [5] | Single element |
[1,2,3,4,5] | [1,2,3,4,5] | Entire array is increasing |
(Always confirm: output just needs to be a valid LIS, not necessarily unique — multiple correct answers may exist for the same input.)
nums? (Confirms whether O(n²) reconstruction is fine, or an O(n log n) approach with reconstruction is expected.)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