A status page simulates an outage spreading through a rack of servers drawn as a grid of strings: "X" is a server that is down, "o" is a healthy server, and "." is an empty slot. Every minute, each healthy server directly above, below, left, or right of a down server also goes down. Empty slots stop the spread.
Write minutesUntilAllDown(rack) that returns how many minutes pass until no healthy server is left, or -1 if some healthy server will never go down. If there are no healthy servers at the start, return 0.
Input: rack = ["Xo.","oo.",".oo"] Output: 4
Minute 1: (0, 1) and (1, 0). Minute 2: (1, 1). Minute 3: (2, 1). Minute 4: (2, 2).
Input: rack = ["Xo.o"] Output: -1
The empty slot keeps the last server healthy forever.
1 <= rack.length, rack[i].length <= 100"X", "o", or ".".Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #427 Minutes Until the Outage Spreads. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.