Problems > Subtraction Game {1,3,7} > Editorial

Subtraction Game {1,3,7} — Solution & Editorial

Back to the Problem

Compute Grundy numbers by the mex of reachable positions, then XOR them (Sprague–Grundy).

Complexity: O(max · |moves| + K)