 All Problems
Remove Duplicate Letters
medium
stack
greedy
string
google
amazon
facebook

Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.

Example 1:

Input: bcabc
Output: abc

Example 2:

Input: cbacdcbc
Output: acdb

Constraints:

  • 1 ≤ s.length ≤ 10⁴
  • s consists of lowercase English letters

Input format: One line — the string.

Output format: Lexicographically smallest result with no duplicate letters.

Run to check your code against the sample cases, or submit to run every case