Print Longest Increasing Subsequence
Given an integer array arr, return the values of its longest strictly increasing subsequence whose index sequence is lexicographically earliest. Compare…
Given an integer array arr, return the values of its longest strictly increasing subsequence whose index sequence is lexicographically earliest. Compare selected original indices at the first difference, not the values at those positions. Equal adjacent chosen values are not a strict increase. Do not modify arr. Return the subsequence values, not its length or indices.
- 1 <= arr.length <= 1000 - -1000000 <= arr[i] <= 1000000 - Duplicates are allowed; each selection retains original index order. - The visualizer supports at most 8 items; larger valid arrays remain coding inputs.
Example 1: input arr = [1,3,2,4,6,5]; output [1,3,4,6]. Indices [0,1,3,4] precede [0,2,3,4]. Choosing a smaller value 2 would not give the earliest index sequence.
Example 2: input arr = [2,2,2]; output [2]. Equal values cannot extend a strictly increasing sequence. The earliest singleton uses index 0.
Example 3: input arr = [4,3,2,1]; output [4]. Every longest subsequence has length 1, so choose the first index, not the smallest value.
Category: Arrays. Topic: dynamic-programming. Difficulty: medium. Patterns: dynamic-programming.