Find the Most Competitive Subsequence LeetCode solution in Python

1
class Solution:
2
def mostCompetitive(self, nums: List[int], k: int) -> List[int]:
3
end = len(nums) - k
4
ans = []
5
for num in nums:
6
while end and ans and num < ans[-1]:
7
ans.pop()
8
end -= 1
9
ans.append(num)
10

11
return ans[:k]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0