Lexicographically Largest Identifier
Updated
Problem statement
Given a string key of lowercase English letters, return the lexicographically largest identifier you can build from it with the steps below.
Positions in key are 1-based, and n is the length of key. The identifier starts empty, and the current range starts as [l, r] = [1, n]. While the range is not empty (l <= r), do one round:
Examples
Example 1
key = "bacab"return = "cba"Pick i = 3 (the only c) and keep the left part [1, 2]. Then pick i = 1 (b) and keep the right part [2, 2], and finally pick i = 2 (a). No identifier can start with a letter larger than c, and no other order of picks gives more than "cba".
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.
More Amazon Online Assessment questions
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Lexicographically Smallest Grid Path with One Letter ChangeInfosys · OAInfosys interview questions
- Longest Repeated Letter Block with Adjacent SwapsIntuit · OAIntuit interview questions
- Binary CircuitAkuna Capital · OAAkuna Capital interview questions
- Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
- Word Wrap with Even JustificationSentry · OA · PHONE SCREENSentry interview questions
- Palindromic StringsNVIDIA · OANVIDIA interview questions
- Get Patch SequenceMorgan Stanley · OAMorgan Stanley interview questions
- Max Number of OperationsSalesforce · OASalesforce interview questions
- Viral Content BalancerTikTok · OATikTok interview questions
- Good Binary StringsBNP Paribas · OA