Code Room
CodingMediumcod-g830
Subject Combinatorial countingLevel Mid–Senior~15 minCommon in Algorithms & data structures interviewsIndustries Software development, Computer games

Question

Two players alternate turns in a game of Nim: there are several piles of stones, and on each turn a player removes one or more stones from a single pile. The player who cannot move (all piles empty) loses. Given the pile sizes, return True if the player who moves first has a winning strategy under optimal play, else False. Use the Sprague-Grundy / Nim-sum theorem: the first player wins iff the XOR of all pile sizes is non-zero.

Implement
nim_first_player_wins(piles: list[int]) → bool
Examples
in[[3,4,5]]outtrue
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.