Back to course home
0% completed
Remove Duplicate Letters (medium)
Problem Statement
Given a string s
, remove all duplicate letters from the input string while maintaining the original order of the letters.
Additionally, the returned string should be the smallest in lexicographical order among all possible results.
A string is in the smallest lexicographical order if it appears first in a dictionary. For example, "abc"
is smaller than "acb"
because "abc"
comes first alphabetically.
Examples:
-
- Input: "babac"
- Expected Output: "abc"
- Justification:
- After removing 1
b
and 1 `a
- After removing 1
.....
.....
.....
Like the course? Get enrolled and start learning!