The Find the Most Competitive Subsequence interview question asks you to find a subsequence of length from an array such that the subsequence is lexicographically smallest. A subsequence is "more competitive" if, at the first index where they differ, it has a smaller element.
Companies like Uber and Google use this to test your understanding of the Monotonic Stack interview pattern. It evaluations your ability to make greedy choices while respecting a global constraint (maintaining a specific length). It’s a test of whether you can identify that a smaller element should always replace a larger one, provided there are enough elements left in the array to still finish a subsequence of length .
This problem is solved using a Monotonic Stack.
nums = [3, 5, 2, 6], .
StackSize + (TotalCount - i - 1) >= k.The Monotonic Stack is the go-to data structure for "Lexicographically Smallest/Largest Subsequence" problems. Practice the condition while (X < stack.top() && can_afford_to_pop) as it is the standard template for these challenges.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Make Array Non-decreasing | Medium | Solve | |
| Maximum Array Hopping Score II | Medium | Solve | |
| The Number of Weak Characters in the Game | Medium | Solve | |
| Minimum Cost Tree From Leaf Values | Medium | Solve | |
| Max Chunks To Make Sorted | Medium | Solve |