Install our extension to search inside any video instantly.

1081. Smallest Subsequence of Distinct Characters | Leetcode Daily - Python

Added:
192 views9likes6:50LeetcodeDaily-amaOriginal Release: 2026-07-19

To find the lexicographically smallest subsequence containing each unique character exactly once, use a greedy approach with a monotonic stack: process characters left to right, and for each character, if it's alphabetically smaller than the last character in the stack and that character appears again later in the string, remove it from the stack to achieve a more alphabetical sequence; this ensures the result is as close to alphabetical order as possible while maintaining the original relative order of characters.