1673. Find the Most Competitive Subsequence

Practice Find the Most Competitive Subsequence for free on NudgeCode: Medium, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Return the lexicographically smallest subsequence of nums with exactly k elements ("most competitive"). Sequences of equal length are compared at the first position where they differ.

Example

nums = [3,5,2,6], k = 2              ->  [2,6]
nums = [2,4,3,3,5,4,9,6], k = 4      ->  [2,3,3,4]

Constraints