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

Question

Two players play with several heaps. From a single chosen heap a player may remove any amount that is in a fixed allowed set S of positive integers (the same S for all heaps). A player who cannot move loses. Given the heap sizes and the sorted allowed-removal set S, return true if the first player wins under optimal play. Constraints: 1 <= number of heaps <= 100, 0 <= each heap <= 10000, 1 <= |S| <= 100, elements of S are distinct positive integers.

Implement
subtraction_game_winner(heaps: list[int], S: list[int]) → bool
Examples
in[[4],[2,3]]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.