Can the First Player Guarantee a Win Taking Credits From Either End

Last updated: November 29, 2026

Quick Overview

A row of credit values is laid out. Two players alternately take one value from either end, and both play optimally. Return whether the first player can finish with a total at least as large as the second player's.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A row of credit values is laid out. Two players alternately take one value from either end, and both play optimally. Return whether the first player can finish with a total at least as large as the second player's.

A game theory interval DP problem used in Meta onsites to test minimax reasoning. The interviewer wants you to define the state as the score difference for the player to move, which keeps the recurrence to one line.

What the Interviewer Expects
  • Model the game over intervals [i, j]
  • Store the best score difference for the player to move
  • Write diff[i][j] = max(v[i] - diff[i+1][j], v[j] - diff[i][j-1])
  • Fill by increasing length or use a 1D array
  • Note the even-length shortcut if it applies
Key Topics to Cover
Interval dynamic programming
Minimax
Game theory
Score difference state
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you return the actual first-player total?
  • What if each player may take up to two items from one end?
  • Why is the first player always able to win when the length is even?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a list of integers v with length 1 to 1000. Players alternate; on each turn a player removes v[i] or v[j] from the current ends and adds it to their total. Return True if the first play...

High-Level Design

Let diff[i][j] be the largest value of (my total minus the opponent's total) that the player to move can guarantee on v[i..j]. Taking v[i] leaves the opponent the interval [i+1, j], where they...


Submit Your Answer
Markdown supported