Find perimeter of shapes formed with 1s in binary matrix
Last Updated : 23 Jul, 2025
Given a matrix of N rows and M columns, consisting of 0's and 1's. The task is to find the perimeter of the subfigure consisting of only 1s in the matrix. The perimeter of a figure is given by the total number of horizontal and vertical linings formed by the boundary 1s of the subfigure. Each line is considered to have a length of 1 unit. Note: There exists only one subfigure consisting of 1s