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
- 1 <= s.length <= 104
- s consists of lowercase English letters.
Starter code (python)
class Solution(object):
def removeDuplicateLetters(self, s):
"""
:type s: str
:rtype: str
"""
Related problems
- Longest Substring Without Repeating Characters (Medium)
- Longest Palindromic Substring (Medium)
- Container With Most Water (Medium)
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.