The final answer is over all positions, since the longest sequence can end anywhere. To reconstruct the subsequence: track for each index.
This records where the sequence jumped from. Start at (the index with max value), follow pointers backward, then reverse. Example: if and , follow . Collect , reverse to get .