Fair Prize Distribution
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The edge case that kills the naive solution here is duplicates on both sides. Amazon candidates reported this one in August 2025, and it looks like a simple sort-and-assign until you hit ties in scores and a prize multiset that can't cover them. Participants with equal scores need the same prize value, higher scores need strictly higher values, and you want the lexicographically smallest result in original order. It's a greedy problem on sorted distinct scores and sorted distinct prize values. If you blank during the live OA, StealthCoder is the invisible safety net that reads the problem and hands you the approach.
The problem
A coding challenge has n participants. Participant i earned score points[i]. There are m available prizes, and values[j] is the value of the j-th prize. Assign one prize value to each participant using the available prize multiset such that: Participants with the same score receive the same prize value. Participants with higher scores receive strictly higher prize values than participants with lower scores. If multiple fair distributions are possible, return the lexicographically smallest distribution in the original participant order. Function findFairDistribution(points: int[], values: int[]) → int[] Examples Example 1 points = [5,5,5] values = [2,2,2,3,3,3] return = [2,2,2] All participants have the same score, so they must receive equal prize values. [2,2,2] is lexicographically smaller than [3,3,3]. Constraints 1 <= points.length, values.length <= 2 * 10^5 1 <= points[i], values[i] <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
Group participants by score and sort the distinct scores ascending. Say there are k distinct scores. Each group needs one prize value, and the values must be strictly increasing, so you need k distinct values from the prize multiset. Also, a group of size s needs s copies of its chosen value, assuming the multiset is consumed. That's the pitfall: duplicates in values only matter if copies are required, so check the count against group size. Sort values, count occurrences, then assign greedily from the smallest feasible value upward, so each group takes the smallest value that is strictly greater than the previous and has enough copies. Smallest per group gives the lexicographically smallest answer in original order, since lower scores get lower values. Watch the input size: n and m go up to 2*10^5, so use sort plus a pointer, not nested loops. StealthCoder is your hedge if the multiset-count wrinkle slips past you mid-assessment.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Fair Prize Distribution 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
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.
Fair Prize Distribution FAQ
How hard is Fair Prize Distribution really?+
Medium. The code is short, but the rules are easy to misread. Ties must match, higher scores need strictly higher values, and the prize multiset limits what you can hand out. If you sort and group first, it's mostly bookkeeping.
What's the core trick?+
Work on distinct scores in ascending order and distinct prize values in ascending order. For each score group, pick the smallest prize value strictly above the previous pick that has enough copies. Then map results back to the original participant order.
What edge cases should I test?+
All scores equal, like [5,5,5]. All scores distinct. Fewer distinct prize values than distinct scores. Prize values with too few copies for a big group. Single participant. Large values up to 10^9, so don't index arrays by value.
What complexity does Amazon expect here?+
With n and m up to 2*10^5, aim for O((n + m) log(n + m)). That means sorting plus a single pass with a pointer or a counted map. Anything quadratic will time out on the large cases.
How do I prepare in 48 hours?+
Practice sort-then-group greedy problems and counting with hash maps. Write this one from scratch twice, with a brute-force checker on tiny inputs. Focus on tie handling and the strictly-increasing constraint, since those are where wrong answers come from.