Lexicographically Largest Distinct-Letter Subsequence
Updated
Problem statement
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) → StringExamples
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.scontains only lowercase English letters.
More Navan interview questions
- Roman to IntegerPHONE SCREEN · Seen Oct 2024
- Sort ColorsPHONE SCREEN · Seen Oct 2024
- Basic CalculatorPHONE SCREEN · Seen Jun 2024
- LRU CachePHONE SCREEN · Seen Jun 2024
- House RobberPHONE SCREEN · Seen May 2024
- House Robber IIPHONE SCREEN · Seen May 2024
- Snake-Case Iterator to Camel CasePHONE SCREEN · Seen Feb 2024
- Time Based Key-Value StoreONSITE INTERVIEW · Seen Dec 2025
- Type-Ahead Prefix MatchesONSITE INTERVIEW · Seen Dec 2024
- Minimum Steps on a Circular Character DialONSITE INTERVIEW · Seen Jan 2024
Similar questions at other companies
- Remove Duplicate Letters for the Largest ResultAmazon · PHONE SCREEN
- Remove K DigitsProcol · PHONE SCREEN
- Minimum Removal for Balanced ParenthesesMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Largest Number After Removing K DigitsGoogle · PHONE SCREENGoogle interview questions
- Minimum Remove to Make Valid ParenthesesBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Smallest Number After Removing k DigitsAdobe · PHONE SCREENAdobe interview questions
- Good Binary StringsBNP Paribas · OA
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Remove K DigitsThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Remove K DigitsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions