Most Frequent Name
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA reported in September 2026 looks like a freebie: count names, return the winner. Then the tie-break shows up. If two names share the top count, you return the lexicographically smallest one, and a naive solution that grabs the first max it sees will fail the hidden tests. It's a hash-table counting problem with one rule that trips people who rush. Case-sensitive comparison matters too, so "Zoe" and "zoe" are different names. If you blank under the clock, StealthCoder runs invisibly on your desktop as a safety net for the live OA and gives you the solution.
The problem
Given a nonempty array of case-sensitive names, return the name that appears most often. If multiple names have the same maximum frequency, return the lexicographically smallest tied name. Function mostFrequentName(names: String[]) → String Examples Example 1 names = ["ana","bob","ana"] return = "ana" Case 1 exercises the documented deterministic contract. Example 2 names = ["zoe","amy","zoe","amy"] return = "amy" Case 2 exercises the documented deterministic contract. Example 3 names = ["solo"] return = "solo" Case 3 exercises the documented deterministic contract. Constraints 1 <= names.length <= 200000. 1 <= names[i].length <= 100. Names contain printable ASCII characters and comparisons are case-sensitive.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The pattern is hash-table counting. Build a map from name to count in one pass, then scan the map for the best entry. Your comparison needs two parts: higher count wins, and on equal counts the smaller string wins. That's the whole trick. The common pitfall is returning the first name that hits the max count, which depends on insertion order and breaks on input like ["zoe","amy","zoe","amy"], where the answer is "amy". Another trap is lowercasing the names, which the case-sensitive rule forbids. With up to 200000 names, O(n) counting plus an O(k) scan, where k is the distinct names, is plenty fast. Sorting all names is unnecessary. Use plain string comparison, which on ASCII is lexicographic by character code. If the tie-break logic slips away mid-assessment, StealthCoder is the hedge that has the clean version ready.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Most Frequent Name 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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Most Frequent Name FAQ
How hard is the Amazon Most Frequent Name question really?+
It's easy on algorithm, with one catch. Counting with a hash map is standard. The part that costs people points is the tie-break rule, which needs lexicographically smallest on equal counts. Handle that and you pass. Skip it and you fail hidden tests.
What's the trick to the tie-break?+
While scanning your count map, update the answer if the count is higher, or if the count is equal and the name is smaller than the current best. One comparison covers both rules. You don't need to sort anything or track a list of tied names.
Do I need to worry about case sensitivity?+
Yes. The problem says comparisons are case-sensitive, so "Ana" and "ana" count separately. Don't normalize or lowercase anything. In ASCII, uppercase letters sort before lowercase, so "Zoe" is smaller than "amy". Use the language's default string comparison and you're correct.
What's the time complexity I should aim for?+
O(n) for the counting pass plus O(k) for the scan over distinct names, with O(k) space. Comparing strings adds a factor up to 100 characters each, which is fine. With n up to 200000, nothing slower than O(n log n) is needed, and sorting isn't required at all.
How do I prepare for this in 48 hours?+
Write it once from scratch in your OA language. Test three cases: a clear winner, a tie like ["zoe","amy","zoe","amy"], and a single-element array. Then do a few other frequency-count problems with tie-break rules. That covers the pattern and the edge case that matters.