Get Largest Number
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon's 'Get Largest Number' problem hits your OA in March 2025, and it's deceptively simple on the surface. You'll need to arrange numbers to form the largest possible value, which sounds straightforward until you realize the trick isn't just sorting numerically. The pattern is sorting with a custom comparator, and StealthCoder is your safety net if the comparator logic blanks you mid-assessment.
Pattern and pitfall
The core trick: you can't sort by numeric value alone. Instead, you need a custom comparator that treats each number as a string and compares concatenations. For two numbers a and b, compare the string ab versus ba to determine order. This catches the edge case where 3 and 30 would normally put 30 first numerically, but 330 is smaller than 303, so 3 comes first. Handle the zero case separately, where if the result is all zeros, return '0'. It's an elegantly brutal comparator problem that candidates often overthink or miss entirely, which is exactly where StealthCoder's real-time pattern matching saves you during the live OA.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Get Largest Number cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as largest number. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Get Largest Number FAQ
Do I really need a custom comparator or can I just sort descending?+
Standard descending sort fails. You must compare concatenations of two numbers as strings. Test with 3 and 30: '330' vs '303' shows 3 should come first, which descending numeric sort would get wrong.
What's the zero edge case everyone forgets?+
If all numbers are zero or the result is '0000...', return the string '0', not '00000'. Check this after building your answer string.
Is this still asked at Amazon in 2025?+
Yes. This is a foundational Amazon pattern, reported March 2025. It tests custom comparator thinking, which Amazon loves for backend and systems roles.
How do I prepare in 48 hours if I don't know comparators?+
Learn that a comparator for this problem returns -1, 0, or 1 based on comparing ab vs ba as strings. Write the comparator function once and you're done. It's one function.
What languages does this work cleanly in?+
Python (custom key function with functools.cmp_to_key), Java (Comparator interface), C++ (custom sort predicate). All handle it fine. Pick what you know.