A whiteboard app exports a rough bitmap of the board as a grid of strings: "#" is ink and "." is empty. Ink cells that touch up, down, left, or right belong to the same shape. Diagonal touching doesn't count.
Write countShapes(board) that returns the number of separate shapes.
Input: board = ["##..","#..#","..##"] Output: 2
The three cells in the top-left form one shape, and the three in the bottom-right form another.
Input: board = ["#.#",".#.","#.#"] Output: 5
The cells only touch diagonally, so each is its own shape.
1 <= board.length, board[i].length <= 200"#" 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 #421 Count Shapes on a Canvas. 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.