994 hands you the rotten oranges, 542 hands you the zeros, 1162 hands you the land. Here nobody hands you anything: you must run a whole first traversal — a DFS, exactly the one in LC 200 — just to discover the seed set, and only then does the machine from the other three pages apply. Phase one paints one island; phase two floods outward from every cell of it at once. The bridge is the water flipped, so the answer is levels minus one — level 1 is the island itself and flips nothing.
"The problem guarantees exactly two disconnected islands of 1s. The goal is to find the minimum number of 0s that need to be flipped to connect them."
"Scan the grid until the first 1 is encountered. Launch DFS to traverse all contiguous 1s belonging to Island A, flipping them to 2 (to mark visited) and pushing every coordinate into a BFS queue."
"Radiate outwards from ALL Island A cells simultaneously in concentric BFS waves through water (0s). The moment a wave steps onto a cell containing 1, it has reached Island B!"
level - 1?"Level 1 is Island A itself, which requires 0 flips. Each subsequent BFS level flips one layer of water cells. Therefore, flips required = level - 1."
level − 1, because level 1 is island A itself and costs nothing. Seeding one cell instead of all of them still often returns the right number, which is precisely why it survives testing.