FastPrepLexicographically Largest Identifier
Problems/Lexicographically Largest Identifier

Lexicographically Largest Identifier

Amazon logoAmazon● HardFULLTIMEOA

Updated Nov 2026

QuestionExamples

Problem statement

Source note: Reported in an Amazon SDE II online assessment (full-time, experienced). The coding question gave the whole task: build an identifier from a lowercase key by picking one letter at a time from a shrinking range, keeping only one side of the pick each round, and return the largest identifier possible. It also gave the limit of 10^5 letters.

The report has no examples, so we wrote our own.

Our version is about 95% the same as the reported question.

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:

The problem statement continues
Pro

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".

02 · Example 2
FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week

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

Interview reports that mention this question

  • Amazon OA · November 2026

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
CodePython 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import heapq
from collections import defaultdict
 
class Solution:
def solve(self, values, queries):
# Build the adjacency structure
n = len(values)
graph = defaultdict(list)
for u, v in queries:
graph[u].append(v)
 
best = [float("inf")] * n
heap = [(0, 0)]
while heap:
cost, node = heapq.heappop(heap)
if cost > best[node]:
continue
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Amazon interview this week

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
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week