Keep One of Each Letter in the Smallest Subsequence

Quick Overview

Keep One of Each Letter in the Smallest Subsequence. Delete characters from s so every distinct input letter appears exactly once, while the remaining sequence is lexicographically smallest among all such subseque

Keep One of Each Letter in the Smallest Subsequence

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Delete characters from s so every distinct input letter appears exactly once, while the remaining sequence is lexicographically smallest among all such subsequences. Retain relative order; arbitrary rearrangement is not allowed. ```cpp string removeDuplicateLetters(string s); ``` ### Examples ```text s = "abacb" -> "abc" s = "bbcaac" -> "bac" ``` ### Constraints - Length is 1 through 10000. - Characters are lowercase English letters.

Overview: Keep One of Each Letter in the Smallest Subsequence. Delete characters from s so every distinct input letter appears exactly once, while the remaining sequence is lexicographically smallest among all such subseque

Amazon logo
Amazon
Date not reported
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Delete characters from s so every distinct input letter appears exactly once, while the remaining sequence is lexicographically smallest among all such subsequences. Retain relative order; arbitrary rearrangement is not allowed.

string removeDuplicateLetters(string s);

Examples

s = "abacb" -> "abc"
s = "bbcaac" -> "bac"

Constraints

  • Length is 1 through 10000.
  • Characters are lowercase English letters.