Remove Duplicate Letters
Medium · Stack & Monotonic Stack · about 25 minutes
Asked at Google, Amazon, ByteDance, Microsoft, Apple.
Given a string s of lowercase letters, remove duplicate letters so every letter appears exactly once, and return the lexicographically smallest result among all ways to do it (the result is a subsequence of s).