Solved LeetCode program · 851 of 1,000
#1140 · Stone Game II
Original English source
Keep a shared stones holding 2, 7, 9, 4, and 4. Keep a shared count of 5. Keep a shared tail as a list of 6 zeros. The spot is count minus 1.
Repeat while spot is at least 0.
The after is spot plus 1. Set item spot of tail to item after of tail plus item spot of stones. Subtract 1 from spot.
Keep a shared table as an empty list of whole numbers. For every slot from 0 to 35, Place -1 into table. Keep a shared gathered of 0.
To gather from start (a whole number) with limit (a whole number). The slot is start times 6 plus limit. If item slot of table is at least 0, set gathered to item slot of table, return. If start is at least count, set gathered to 0, set item slot of table to 0, return. The reach is limit times 2. If reach is more than count minus start, set reach to count minus start. The best is 0.
For every take from 1 to reach.
The grown is limit. If take is more than grown, set grown to take. Gather from start plus take with grown. The offered is item start of tail minus gathered. If offered is more than best, set best to offered. Set item slot of table to best. Set gathered to best.
Gather from 0 with 1. Show gathered.
Expected stdout
10