Trains the technique from
LeetCode 2258Escape the Spreading FireThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A quarry floor is laid out as m rows of n panels. panels[i][j] reads 0 for a firm panel, 1 for a panel already under slurry, and 2 for a pillar. You stand on the ramp at panels[0][0] and want to reach the shed at panels[m - 1][n - 1], and both of those are firm.
Time passes in whole minutes, and each minute of the walk holds two things in this order:
Pillars stop the slurry just as they stop you. If the slurry creeps onto the panel you are standing on, it has you. Stepping onto the shed ends the walk, so slurry creeping onto the shed during that same minute does not.
Before setting off you may linger on the ramp for a whole number of minutes, and the slurry creeps during every one of them. Once you set off you step every minute until you are on the shed.
Return the largest number of minutes you can linger and still reach the shed. Return 10^9 if you can linger for any number of minutes whatsoever, and -1 if you cannot reach the shed even by setting off at once.
Example 1
The pillars leave one way down off the top row, so the walk to the shed is six steps and the slurry, starting at the far end of the top row, needs nine minutes to follow it there. Lingering three would land you on the shed as the slurry arrives, which is allowed, but it would also put the slurry on the panel before the shed while you were still standing on it. Lingering two keeps you a minute clear the whole way.
Example 2
The slurry sits one panel from the shed and covers it after two minutes, while the shortest way around the wet middle panel takes four steps. The slurry is there first even if you leave at once.
Example 3
Pillars hem the one wet panel in on all four sides, so the slurry never moves. Nothing on the way to the shed is ever wet, so the lingering has no ceiling.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_minutes(panels: list[list[int]]) -> int:public int maximumMinutes(int[][] panels)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.