Minimum Starting Health in a Grid
Updated
Problem statement
You are given a non-empty rectangular integer matrix grid. Start at the top-left cell and reach the bottom-right cell by moving only right or down.
Entering a cell immediately adds that cell's value to your current health. Health may become exactly 0, but it must never become negative.
Return the minimum nonnegative health required before entering grid[0][0] so that at least one valid path reaches the destination without health becoming negative.
Function
minimumStartingHealth(grid: int[][]) → intExamples
Example 1
grid = [[-2,-3,3],[-5,-10,1],[10,30,-5]]return = 6With starting health 6, the path right, right, down, down produces health 4, 1, 4, 5, 0. Starting with less would make health negative along every valid path.
Example 2
grid = [[5]]return = 0Starting with 0 is allowed, and entering the only cell raises health to 5.
Example 3
grid = [[-4,10],[-10,-1]]return = 4Starting with 4 and moving right then down gives health 0, 10, 9. Any smaller start becomes negative in the first cell.
Constraints
1 <= grid.length <= 200.1 <= grid[i].length <= 200.- Every row has the same length.
grid.length * grid[0].length <= 40000.-1000 <= grid[i][j] <= 1000.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Cherry PickupInfosys · OAInfosys interview questions
- Safest Shortest Path Through a GridSnowflake · OASnowflake interview questions
- Minimum Cost Path with TeleportationsAmazon · OA
- Largest Two Non-Overlapping Buildable SquaresAmerican Express · OAAmerican Express interview questions
- Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
- Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
- Increasing Paths, part 2Hudson River Trading · OAHudson River Trading interview questions
- Timed Coin Collection in a 2×N GridAtlassian · OAAtlassian interview questions
- Maximum Sum RectangleDeloitte · OADeloitte interview questions
- Longest Increasing Path in a MatrixNutanix · OANutanix interview questions