Trains the technique from
LeetCode 1510Stone Game IVThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two riggers, Ada and Boaz, share one spool holding n whole metres of cable. Ada acts first and then they act alternately.
On a turn the rigger whose turn it is must cut away exactly k * k metres for some positive whole number k. The cut may not exceed what is left on the spool, and skipping a turn is not allowed. A rigger who starts a turn with an empty spool has no legal cut and loses the duel.
Both riggers see the whole spool and never misplay. Return True when Ada can win against every defence, and False when Boaz can.
Example 1
Ada opens by cutting 16 metres, and from the length that is left she has an answer to every defence Boaz plays, so Boaz is the rigger who eventually starts a turn with nothing to cut. An opening cut of 81 metres also wins for her.
Example 2
Ada has only a handful of legal openings from 39 metres, and Boaz forces the win after each of them.
Example 3
Ada opens by cutting 25 metres, leaving 5 metres on the spool, and wins from there.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def winner_square_game(n: int) -> bool:public boolean winnerSquareGame(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.