Coin Game From The Ends
Reported by candidates from Tekion's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
A row of six coins, 20, 30, 2, 2, 2, 10, and two players grabbing from the ends. That's the Tekion OA reported in September 2026, and the hinted tag says simulation, but don't buy it. Greedy simulation loses here. It's an interval DP game problem: both players play optimally, and you return true if the first player ties or beats the second. If you've got the invite and 48 hours, learn the score-difference recurrence below. StealthCoder sits invisibly on your screen as a safety net if you blank during the live OA.
The problem
You are given an even-length integer array coins representing a row of coin values. Two players take turns. On a turn, a player must take the coin at the current left end or the current right end of the remaining row. The first player starts. Both players play optimally to maximize their own total. Return true if the first player can obtain a total at least as large as the second player's total, and false otherwise. What the interview report shared The report described an even-length coin row where players alternately take a coin from either end, A moves first, and the player with the higher total wins. Function firstPlayerWins(coins: int[]) → boolean Examples Example 1 coins = [20,30,2,2,2,10] return = true The six coins sum to 66. Optimal play lets the first player collect 42 and the second collect 24, so the first player wins. Example 2 coins = [8,15,3,7] return = true Taking 7 first forces the later choice of 15. The first player totals 22 and the second totals 11. Constraints 2 <= coins.length <= 500. coins.length is even. 1 <= coins[i] <= 10^6.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to track score difference, not both totals. Define dp[i][j] as the best (my total minus opponent total) the current mover can get on coins i..j. Then dp[i][j] = max(coins[i] - dp[i+1][j], coins[j] - dp[i][j-1]). Base case dp[i][i] = coins[i]. Return dp[0][n-1] >= 0. With n up to 500, O(n^2) is about 250,000 states, which is fine. The common pitfall is greedy, taking the bigger end each turn. Example 2 breaks it: [8,15,3,7] looks like 8 first, but you want 7 so the opponent is forced into the worse choice. Another pitfall is using > 0 instead of >= 0, since ties count as a win. Also note that with an even length the first player can always at least tie, so true is guaranteed, but code the DP anyway. If you freeze during the live Tekion OA, StealthCoder can supply the recurrence as a hedge.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Coin Game From The Ends 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 predict the winner. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Tekion's OA.
Tekion 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.
Coin Game From The Ends FAQ
What's the trick in the Tekion coin game problem?+
Stop tracking two totals. Track the difference the current mover can force on a subarray. dp[i][j] = max(coins[i] - dp[i+1][j], coins[j] - dp[i][j-1]). The opponent's best play is subtracted automatically, so one table handles both players.
Why doesn't greedy work here?+
Taking the larger end ignores what you expose for the opponent. In [8,15,3,7], grabbing 8 looks natural, but taking 7 first leaves the opponent in a bad spot and you end up with 22 to 11. You have to look ahead, which is what the DP does.
Is it true that the first player always wins with even length?+
Yes, with an even number of coins the first player can lock in either all odd-indexed or all even-indexed coins, so they can always tie or win. Returning true would pass, but the DP is the safe, honest answer if the checker or follow-ups change.
What's the complexity and will n = 500 pass?+
Interval DP is O(n^2) time and can be O(n) space with a rolling array. At n = 500 that's roughly 250,000 states, trivially fast. Values reach 10^6 times 500, so sums fit in a 32-bit int, but a long is harmless.
How do I prepare for this in 48 hours?+
Write the difference DP from scratch twice, once top-down with memoization and once bottom-up by interval length. Test on [8,15,3,7] and [20,30,2,2,2,10]. Then practice a couple of related two-player game problems so the max-minus-opponent pattern feels automatic.