Tap here to switch tabs
Problem
Submissions

Problem: Can I Win

Can I Win has two players choose unused numbers from one through a maximum, adding each to a running total. Return whether the first player can force a win at or above the target total, with optimal play.

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

Can I Win has two players choose unused numbers from one through a maximum, adding each to a running total. Return whether the first player can force a win at or above the target total, with optimal play.

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`