Print Longest Increasing Subsequence
Implement printLIS
Given an array of integers, reconstruct one actual longest strictly increasing subsequence rather than just its length — an in-order run of elements that keeps climbing at every step. Since several different runs can tie for the longest length, ties are broken by always preferring the earliest-finishing chain, so the result stays the same no matter which language or approach produces it.
The same length-only table used to compute how long the answer is can also record enough to rebuild it: whichever earlier index actually produced a given index's best length is worth remembering as that index's predecessor. Once every index has been filled in along with its predecessor, the index holding the overall best length marks the end of the answer, and walking predecessor links backward from there — either through a recursion that unwinds in the right order, or through a loop that fills a result array from its last slot toward its first — replays exactly the choices that built it, turning the stored lengths back into one concrete increasing run.
Example 1:
Input: nums = [11,4,7,2,9,6,14,3]
Output: [4,7,9,14]
Example 2:
Input: nums = [2,5,2,8,6,9]
Output: [2,5,8,9]
Example 3:
Input: nums = [5,5,5,5,5,5,5]
Output: [5]
+ 7 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ nums.length ≤ 12 - ●
-1000 ≤ nums[i] ≤ 1000 - ●
If more than one longest increasing subsequence exists, return the one that ends at the earliest-finishing chain — built by always preferring the smallest-index predecessor whenever two predecessors would extend a chain to the same length
nums =
[11, 4, 7, 2, 9, 6, 14, 3]