Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Stone Game II

Hard

Topics
ArrayMathDynamic ProgrammingGame Theory

Alice and Bob play with piles of stones nums (pile i has nums[i] stones). Alice moves first with M = 1. On a turn a player takes all stones from the first X remaining piles where 1 <= X <= 2M, then M becomes max(M, X). Both play optimally to maximize their own stones. Return the maximum stones Alice can collect.

Example 1

Input:  nums = [2,7,9,4,4]
Output: 10

Example 2

Input:  nums = [1,2,3,4,5,100]
Output: 104

Constraints

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 10^4
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access