Interview Questions/Coding/Minimum Shield for Crystal Maze

Minimum Shield for Crystal Maze

Preview mode. Log in to edit, run, submit, and save progress.

Hard

Minimum Shield for Crystal Maze

A robot crosses a crystal maze from the top-left cell to the bottom-right cell, moving only right or down. Each cell either drains shield power with a negative value or restores shield power with a positive value. The robot is disabled if its shield ever drops below 1. Return the minimum starting shield needed to safely reach the exit.

Examples

Example 1
Input:
maze = [[-2,-3,3],[-5,-10,1],[10,30,-5]]
Output:
7

Approach hint

Forward greedy fails.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

solution.cpp