Tap here to switch tabs
Problem
Submissions

Problem: Can I Win

med
30 min
Try to solve the Can I Win problem.

Statement

You are given two integers, maxChoosableInteger and desiredTotal.

Two players take turns choosing an unused integer from 11 through maxChoosableInteger. Each chosen integer is added to a running total. The player whose choice makes the running total greater than or equal to desiredTotal wins.

Both players play optimally. Return true if the first player can force a win; otherwise, return false.

Implement canIWin(maxChoosableInteger, desiredTotal). The parameter maxChoosableInteger is an integer, desiredTotal is an integer, and the method returns a boolean.

Constraints:

  • 1≤1 \leq maxChoosableInteger ≤20\leq 20

  • 0≤0 \leq desiredTotal $\leq 300`

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Can I Win

med
30 min
Try to solve the Can I Win problem.

Statement

You are given two integers, maxChoosableInteger and desiredTotal.

Two players take turns choosing an unused integer from 11 through maxChoosableInteger. Each chosen integer is added to a running total. The player whose choice makes the running total greater than or equal to desiredTotal wins.

Both players play optimally. Return true if the first player can force a win; otherwise, return false.

Implement canIWin(maxChoosableInteger, desiredTotal). The parameter maxChoosableInteger is an integer, desiredTotal is an integer, and the method returns a boolean.

Constraints:

  • 1≤1 \leq maxChoosableInteger ≤20\leq 20

  • 0≤0 \leq desiredTotal $\leq 300`