A warehouse robot visits a rectangular grid of workstations. It starts at the top-left workstation and must reach the bottom-right workstation. Each move takes it one workstation right or down.
Each workstation changes the battery level. A negative value consumes battery units, a positive value adds battery units, and zero leaves it unchanged.
Apply the change at every visited workstation, including the first and last. Moving has no additional battery cost. The battery has no maximum charge limit and must always remain at 1 unit or more, including after the final workstation.
int minimumStartingCharge(List<String> chargeChanges)
chargeChanges: rows listed from top to bottom. Each string contains the row's battery changes from left to right, separated by commas.1 ≤ chargeChanges.size() ≤ 200-1,000 and 1,000, inclusive.Call: minimumStartingCharge(chargeChanges = ["-2,-5,9", "1,-4,-3"])
Output: 8
Choose right → right → down. Starting with 8 units, the battery levels become 6 → 1 → 10 → 7. No route works with a smaller starting charge.
Call: minimumStartingCharge(chargeChanges = ["2,-7", "-4,-2"])
Output: 5
Choose down → right. Starting with 5 units, the battery levels become 7 → 3 → 1. Any smaller starting charge fails on every route.
Call: minimumStartingCharge(chargeChanges = ["7"])
Output: 1
The only workstation adds 7 units. Starting with 1 unit is enough, leaving 8 units after the change.