Get Score Difference
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're looking at Amazon's December 2023 competitive game problem. Two players alternating picks from a pool of positive integers, each trying to maximize their own score. No tricks with the rules, but the strategy is where most candidates miss the pattern. Both players play optimally, which means you need to think recursively about what each player will do on their turn. StealthCoder can feed you the pattern in real time if you freeze on the approach.
The problem
\ Amazon Games has recently unveiled a two-player competitive game featuring a collection of positive integers, each symbolizing a score value.\ \ On each turn, a player selects any number from the collection, adds it to their personal score, and removes that number from the collection. The players take alternate turns, with Player 1 always starting the game. This process repeats until there are no numbers left.\ \ Both players aim to maximize their own scores by making optimal choices.\
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is a classic game theory problem that reduces to dynamic programming with memoization or recursion. The key insight: each player, when it's their turn, will pick the number that gives them the maximum advantage over their opponent. You're not just maximizing your own score; you're maximizing the difference between your score and theirs. Work backwards from the end state. At each turn, a player can pick any remaining number and recursively solve for the best outcome from that choice. The trick most miss is framing it as score difference, not absolute score. Implement it with a recursive function that tracks available numbers and whose turn it is, using memoization to avoid recomputation. StealthCoder as a safety net means if you blank on the recursion structure, you get the pattern spelled out live.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Get Score Difference 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
This OA pattern shows up on LeetCode as predict the winner. 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. 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.
Get Score Difference FAQ
Is this really asking for the score difference, or just Player 1's final score?+
The problem title is 'Get Score Difference,' so you're computing Player1Score minus Player2Score as the return value. Both players play optimally to maximize this value from their perspective when it's their turn.
How do I code this without brute force?+
Use recursion with memoization. State is the set of remaining numbers and whose turn it is. At each state, try every possible pick and take the one that maximizes score difference. Memoize by encoding the remaining set (bit mask or sorted tuple) and player turn.
What's the most common mistake candidates make?+
Forgetting that Player 2 also plays optimally. You can't just greedily pick the largest number every time. You have to simulate what Player 2 will do when it's their turn and pick accordingly.
Can I solve this iteratively or is recursion mandatory?+
Recursion with memoization is cleanest. You could attempt bottom-up DP by sorting states by remaining count, but the state space is hard to enumerate. Stick with top-down recursion.
How much time should I spend on this in the live OA?+
If you spot the game theory and recursion pattern immediately, 15-20 minutes to code and test. If you're unsure, write out a small example by hand first to confirm both players are playing optimally.