Approach Summary
Monotonic-increasing stack. For each char: pop while stack top > current AND the top appears again later. Skip chars already in the stack.
How to Recognize This Pattern
- "Smallest lexicographic subsequence with one of each char"
- Greedy stack: pop larger if a future occurrence exists
Complexity Analysis
Time Complexity
O(n)
Space Complexity
O(1)
Tags
String Stack Greedy Monotonic Stack