Code Room
CodingHardcod-g712
Subject Game theoryLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Two players play a game with several independent piles of stones. On each turn a player picks one pile and removes a strictly positive number of stones that must be a perfect square (1, 4, 9, ...). A player who cannot move loses. Given the initial pile sizes, return true if the first player (to move) wins with optimal play, else false. Constraints: 1 <= number of piles <= 50, 0 <= each pile <= 10000.

Implement
first_player_wins(piles: list[int]) → bool
Examples
in[[1]]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.