FastPrepRemove Duplicate Letters for the Largest Result
Problems/Remove Duplicate Letters for the Largest Result

Remove Duplicate Letters for the Largest Result

Amazon logoAmazon● HardFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon SDE2 interview list as the lexicographically largest reversal of Remove Duplicate Letters. Problem match confidence: approximately 99%.

Given a lowercase string s, remove characters so that every distinct letter appears exactly once. The remaining characters must preserve their original relative order.

Return the lexicographically largest possible result.

Function

largestUniqueLetters(s: String) → String

Examples

Example 1

s = "bcabc"return = "cab"

The subsequence cab contains each distinct letter once and is lexicographically largest.

Example 2

s = "cbacdcbc"return = "cbad"

Keeping the early c and b allows the largest valid prefix.

Example 3

s = "bbcaac"return = "bca"

The best unique-letter subsequence is bca.

Constraints

  • 1 ≤ s.length ≤ 100000.
  • s contains only lowercase English letters.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public String largestUniqueLetters(String s) {
        // write your code here
    }
}
Checking account…