Find the Most Competitive Subsequence
Given an integer array nums and a positive integer k, you need to find the most competitive subsequence of nums with exactly k elements.
A subsequence is formed by removing some (possibly zero) elements from the original array while maintaining the relative order of remaining elements. Think of it as selecting elements from left to right without changing their positions.
What makes one subsequence "more competitive" than another? Simple - it's lexicographically smaller! When comparing two subsequences of the same length, the one that has a smaller number at the first differing position wins.
Example: [1,3,4] beats [1,3,5] because at the third position, 4 < 5.
Your goal is to find the subsequence that would come first if all possible subsequences of size k were sorted in ascending order.
Input & Output
Constraints
- 1 โค nums.length โค 105
- 0 โค nums[i] โค 109
- 1 โค k โค nums.length
- The answer is guaranteed to be unique