Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

Solution: Remove Duplicate Letters

Problem Statement

Given a string s, remove duplicate letters so that every letter that appears in s appears exactly once in the result. You may only delete characters. The letters that survive keep the order they had in s.

Among all the results you can reach that way, return the one that is smallest in lexicographical order.

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.

Note that this does not mean sorting the letters. "zabccde" gives

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content