Install our extension to search inside any video instantly.

LeetCode 1081 | Smallest Subsequence of Distinct Characters | Monotonic Stack Trick | Python

Added:
100 views1likes11:54statlearntechOriginal Release: 2026-07-19

To find the lexicographically smallest subsequence containing all unique characters from a string, use a monotonic stack where you greedily maintain characters in increasing order; when encountering a smaller character than the stack top, pop the larger character if it appears again later (tracked via frequency map), ensuring the result contains each unique character exactly once in the smallest possible lexicographical order.