Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
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

.....

.....

.....

Like the course? Get enrolled and start learning!