Find the Most Competitive Subsequence
Given an integer array nums and a positive integer k, return the most competitive subsequence of nums of size k.
An array's subsequence is a resulting sequence obtained by erasing some (possibly zero) elements from the array.
A subsequence a is more competitive than a subsequence b of the same length if, in the first position where a and b differ, subsequence a has a number less than the corresponding number in b.
Example 1
Input
nums = [3,5,2,6], k = 2Output
[2,6]Among every possible subsequence of size 2,
[2, 6] is the most competitive.Example 2
Input
nums = [2,4,3,3,5,4,9,6], k = 4Output
[2,3,3,4]The most competitive subsequence of size 4 is
[2, 3, 3, 4].Constraints
- 1 <= nums.length <= 10^5
- 0 <= nums[i] <= 10^9
- 1 <= k <= nums.length