 Find perimeter of shapes
##### Submissions: 538   Accuracy: 37.75%   Difficulty: Easy   Marks: 2

Given a matrix mat[][] of n rows and m columns, consisting of 0’s and 1’s. The task is to complete the function findPerimeter which returns an integer denoting the perimeter of sub-figures consisting of only 1’s in the matrix.

For example
Perimeter of single 1 is 4 as it can be covered from all 4 side. Perimeter of double 11 is 6.

```
|  1  |           |  1    1  |
```

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. The first line of each test case contains two space separated n and m denoting the size of the matrix mat[][] . Then in the next line are n*m space separated values of the matrix.

Output:
For each test case in a new line print the perimeter of sub-figure consisting only 1’s in the matrix.

Constraints:
1<=T<=100
1<=n, m<=20

Example(To be used for expected output):
Input:

2
1 2
1 1
3 3
1 0 0 1 0 0 1 0 0

Output:
6
8

Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harshit Sidhwa
Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.