Trains the technique from
LeetCode 934Shortest BridgeThis 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 survey of a frozen bay comes back as chart, a square grid where 1 marks a cell of solid ice and 0 marks open water. Two ice cells belong to the same floe when they share an edge; touching only at a corner does not join them. The chart shows exactly two floes.
A crew joins the floes by laying planks. Laying a plank fills one water cell and turns it into part of the walkable surface, again joined to whatever it shares an edge with.
Return the smallest number of water cells the crew has to plank so that the two floes end up on one connected walkable surface.
Example 1
The two ice cells touch only at a corner, so they are separate floes. Planking the water cell at row 1, column 0 gives a surface where all three cells share edges.
Example 2
Planking the water cell at row 1, column 0 puts it edge to edge with the ice above and the ice below, joining the two floes.
Example 3
Planking the cells at row 0 column 1, row 0 column 2, row 0 column 3 and row 1 column 3 leaves a chain of edge-sharing cells running from one floe to the other, using 4 planks.
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 min_planks(chart: list[list[int]]) -> int:public int minPlanks(int[][] chart)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.