Company: Linkdin_2feb
Difficulty: medium
Count Matching Regions Problem Description Images are stored in the form of a grid. Image recognition is possible by comparing grids of two images and checking if they have any matching regions. There are two grids where each cell of the grids contains either 0 or 1. If two cells share a side then they are adjacent. Cells that contain 1 form a connected region if any cell of that region can be reached by moving by row or column through the adjacent cells that contain 1. Overlay the first grid onto the second and if a region of the first grid completely matches a region of the second grid, the regions are matched. Count the total number of such matched regions in the second grid. Examples Example 1: Input: grid1 = ["111", "100", "100"], grid2 = ["111", "100", "101"] Output: 1 Explanation: There are 2 regions in the second grid: {(0,0),(0,1),(0,2),(1,0),(2,0)} and {(2,2)}. Regions in grid 1 cover the first region of grid 2, but not the second region. There is 1 matching region. Example 2