Trains the technique from
LeetCode 130Surrounded RegionsThis 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 gasket sheet is inspected cell by cell and handed to you as sheet, a grid of rows rows and cols columns. Every cell carries one character: "X" for solid material, "O" for an open channel.
Two open cells belong to the same channel network when they share a side, so up, down, left or right. Meeting only at a corner joins nothing.
A network holding at least one cell on the outer rim of the sheet can vent to the air outside, and the plant leaves it alone. A network with no cell on the rim is a trapped pocket, and every cell of such a network is filled with solid material.
Do the filling where the sheet already sits. Overwrite the cells of sheet itself instead of assembling a second grid of the same size, then hand sheet back.
Example 1
The two corner cells sit on the rim and stay open. The middle cell only meets them at corners, which joins nothing, so it is a pocket of its own and gets filled.
Example 2
The four open cells form one network ringed by solid material on all sides, so the whole pocket is filled and the sheet ends up solid.
Example 3
All three open cells are one network, and two of them lie on the rim, so the network vents and the sheet is returned untouched.
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 seal_pockets(sheet: list[list[str]]) -> list[list[str]]:public char[][] sealPockets(char[][] sheet)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.