Perimeter
Problem Statement
You have a square grid with length n. Each cell in the grid can be either 1 or 0.
Return the length of the perimeter required to surround all the 1 cells in the grid.

Input
Your first line will contain n.
Your next n lines will each contain n grids of 1's and 0s.
Output
A single integer representing the unit perimeter required to surround all the 1 cells in the grid.
Constraints
For all test cases:
- 1≤n≤103
- All cells will be either 1 or 0.
Example 1
3
010
111
010
12
Example 2
4
0110
1110
0000
0110
16
Example 3
2
01
10
8
Python Template
n = int(input())
grid = [list(map(int, input())) for _ in range(n)]
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.