A vector tool draws a stroke around the shape you click. The canvas is a grid of strings where "#" is filled and "." is empty. Filled cells that touch up, down, left, or right form one shape.
Write outlineLength(canvas, row, col) that returns the length of the outline of the shape containing cell (row, col): the number of cell sides of that shape that touch an empty cell or the edge of the canvas. If (row, col) is empty, return 0.
Input: canvas = ["##.","#..","..#"], row = 0, col = 0 Output: 8
The L-shape has 3 cells with 12 sides, and 2 pairs of sides are shared inside the shape, leaving 12 - 4 = 8.
Input: canvas = ["##.","#..","..#"], row = 2, col = 2 Output: 4
The single cell in the corner has 4 outside sides.
1 <= canvas.length, canvas[i].length <= 100(row, col) is inside the canvas.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 #422 Outline Length of a Selected Shape. 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.