All problems
Subtraction Game Win Check
Problem
In a game where each player removes between 1 and k stones from a pile, return True if the first player can force a win with perfect play, and False otherwise.
The losing positions are exactly the multiples of k + 1, because every move leaves a non-multiple that the opponent can restore. Return False for 0 stones.
Hint
Whatever the opponent removes, you can remove enough to complete a group of k + 1.
Test cases
case 1
in: [10,3]
expected: true
case 2
in: [8,3]
expected: false
case 3
in: [1,1]
expected: true
case 4
in: [0,3]
expected: false
case 5
in: [7,3]
expected: true
Starter codePython
def subtraction_game_win(n, k):
# Your code here
pass5 test cases · run your code against them in the editor