Zepruv › Coding problems

Remove Duplicate Letters

Medium · String, Stack, Greedy, Monotonic Stack

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: s = "bcabc"
Output: "abc"

Example 2

Input: s = "cbacdcbc"
Output: "acdb"

Constraints

Starter code (python)

class Solution(object):
    def removeDuplicateLetters(self, s):
        """
        :type s: str
        :rtype: str
        """
        

Related problems

Previous: Minimum Height Trees · Next: Maximum Product of Word Lengths · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.