Problems > Remove Three, Four, or Five > Editorial

Remove Three, Four, or Five — Solution & Editorial

Back to the Problem

Grundy DP: g[n] = mex of reachable values; non-zero means the first player wins.

Complexity: O(max n · moves)