Skip to main content
Medium Monotonic Stack Medium frequency

Remove Duplicate Letters

Open on LeetCode

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

This site is free. If these guides are helping your prep, consider buying me a coffee. ☕

Support →
Buy me a coffee