A map editor cleans up drawings: any empty area completely closed in by walls should be filled in. The map is a grid of strings where "X" is a wall and "O" is empty. Empty cells that touch up, down, left, or right form one area.
An area is enclosed if none of its cells is on the edge of the map. Write fillGaps(map) that returns a new map, as an array of strings, where every cell of every enclosed area becomes "X". Areas that touch the edge stay as they are.
Input: map = ["XXXX","XOOX","XXOX","XOXX"] Output: ["XXXX","XXXX","XXXX","XOXX"]
The three Os in the middle can't reach the edge, so they're filled. The O on the bottom row touches the edge and stays.
Input: map = ["OO","OO"] Output: ["OO","OO"]
Every empty cell is on the edge.
1 <= map.length, map[i].length <= 200"X" or "O".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 #424 Fill Enclosed Gaps. 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.