Trains the technique from
LeetCode 2029Stone Game IXThis 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.
A pallet holds a row of crates, and crate i weighs weights[i]. Two loaders, One and Two, empty the pallet in turns, and One always moves first.
On a turn the loader to move must take exactly one crate that is still on the pallet, any one of them, and put it on a shared heap. Straight after a crate lands on the heap, the total weight of every crate now on the heap is read off. If that total is divisible by 3, the loader who has just moved loses and the duel stops there.
If the pallet runs empty and neither loader has lost, Two wins.
Both loaders play as well as the position allows. Return true if One wins the duel, and false otherwise.
Example 1
One opens by taking the crate of weight 8, so the heap weighs 8, which is not divisible by 3. Two must then take the crate of weight 4 or the crate of weight 7, bringing the heap to 12 or to 15, and both of those are divisible by 3.
Example 2
One has to open with one of the three crates, leaving a heap of 6, 9 or 12, and every one of those totals is divisible by 3, so One loses on the opening move.
Example 3
Whichever crate One opens with, the heap holds 5 or 11 and the duel continues. Two then takes the remaining crate, bringing the heap to 16, which is not divisible by 3, and with the pallet empty and nobody having lost the win goes to Two.
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 first_player_wins(weights: list[int]) -> bool:public boolean firstPlayerWins(int[] weights)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.