Stone Game II
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Piles of stones stand in a row; piles[i] is the number of stones in pile i. Alice and Bob alternate turns, Alice first, with a value M that starts at 1.
On a turn, the player takes **all** stones from the first X remaining piles, where 1 <= X <= 2M (and X cannot exceed the number of piles left). Then M becomes max(M, X). The game ends when no piles remain.
Both players play optimally to maximise their own stone count. Return the number of stones Alice ends up with.
Examples
Constraints
- 1 <= piles.length <= 100
- 1 <= piles[i] <= 10^4
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.