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.
Perimeter of single 1 is 4 as it can be covered from all 4 side. Perimeter of double 11 is 6.
| 1 | | 1 1 |
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.
For each test case in a new line print the perimeter of sub-figure consisting only 1’s in the matrix.
Example(To be used for expected output):
1 0 0 1 0 0 1 0 0
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.
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.