FastPrepCoin Game From The Ends
Problems/Coin Game From The Ends

Coin Game From The Ends

Tekion logoTekion● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report described an even-length coin-row end-taking game where the first player tries to beat the second. It did not name a return type; this practice version asks whether the first player can obtain at least as much as the second under optimal play and matches the visible source at about 90%.

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.

More Tekion problems

  • Peak Resource Usage Across Weighted IntervalsPHONE SCREEN · Seen Sep 2026
  • Largest Rectangle in HistogramONSITE INTERVIEW · Seen Sep 2026
  • Next Greater Element to the RightONSITE INTERVIEW · Seen Sep 2026
All Tekion interview questionsSee Tekion hiring insights
Saved
class Solution {
    public boolean firstPlayerWins(int[] coins) {
      // Write your code here.
    }
}
Checking account…