In the "100 game" two players take turns adding, to a running total, any integer from 1 to 10. The player who first causes the running total to reach or exceed 100 wins.

What if we change the game so that players cannot re-use integers? For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.

Given two integers maxChoosableInteger and desiredTotal, return true if the first player to move can force a win, otherwise, return false. Assume both players play optimally.

Input & Output

Example 1 — First Player Can Win Immediately
$ Input: maxChoosableInteger = 10, desiredTotal = 11
Output: false
💡 Note: First player cannot guarantee a win. If player 1 picks any number from 1-10, player 2 can pick a number that reaches or exceeds 11.
Example 2 — Small Numbers, Strategic Play
$ Input: maxChoosableInteger = 10, desiredTotal = 40
Output: true
💡 Note: First player can force a win by making strategic choices that put the second player in losing positions.
Example 3 — Immediate Win
$ Input: maxChoosableInteger = 5, desiredTotal = 5
Output: true
💡 Note: First player wins immediately by choosing 5, which reaches the desired total.

Constraints

  • 1 ≤ maxChoosableInteger ≤ 20
  • 0 ≤ desiredTotal ≤ 300

Visualization

Tap to expand
Can I Win: Game Theory Problem (maxChoose=4, target=6)P1P2Player 1Player 2Available Numbers1, 2, 3, 4Target: 6Goal: First to reach total ≥ 6 winsQuestion: Can Player 1 force a win?
Understanding the Visualization
1
Game Setup
Two players, numbers 1 to maxChoose, target total
2
Strategy
Each player tries to force opponent into losing position
3
Result
First player wins if any move guarantees victory
Key Takeaway
🎯 Key Insight: Use minimax with memoization - the current player wins if any move forces the opponent into a losing position
Asked in
Google 25 Microsoft 18 Amazon 15
98.6K Views
Medium Frequency
~35 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen