Skip to content

Practice Remove Duplicate Letters

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#316
LeetCode Problem

Remove Duplicate Letters

Problem Statement

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: Example 2: Constraints: Note: This question is the same as 1081: https://leetcode.com/problems/smallest-subsequence-of-distinct-characters/

Source: Remove Duplicate Letters on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "bcabc"
Output
"abc"

# Example 2

Input
s = "cbacdcbc"
Output
"acdb"

Constraints

1 <= s.length <= 10^4
s consists of lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Remove Duplicate Letters.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.