 All Problems
Find the Most Competitive Subsequence
medium
arrays
stack
greedy
amazon
google

Given an integer array nums and integer k, return the most competitive subsequence of length k. A subsequence is more competitive if at the first differing index it has a smaller element.

Example 1:

Input: 3 5 2 6
k: 2
Output: 2 6

Example 2:

Input: 2 4 3 3 5 4 9 6
k: 4
Output: 2 3 3 4

Input format: Line 1: space-separated array. Line 2: k.

Output format: Space-separated subsequence.

Run to check your code against the sample cases, or submit to run every case