Welcome to Subscribe On Youtube
Formatted question description: https://leetcode.ca/all/2123.html
2123. Minimum Operations to Remove Adjacent Ones in Matrix
You are given a 0-indexed binary matrix
grid. In one operation, you can flip any
grid to be
A binary matrix is well-isolated if there is no
1 in the matrix that is 4-directionally connected (i.e., horizontal and vertical) to another
Return the minimum number of operations to make
Input: grid = [[1,1,0],[0,1,1],[1,1,1]] Output: 3 Explanation: Use 3 operations to change grid, grid, and grid to 0. After, no more 1's are 4-directionally connected and grid is well-isolated.
Input: grid = [[0,0,0],[0,0,0],[0,0,0]] Output: 0 Explanation: There are no 1's in grid and it is well-isolated. No operations were done so return 0.
Input: grid = [[0,1],[1,0]] Output: 0 Explanation: None of the 1's are 4-directionally connected and grid is well-isolated. No operations were done so return 0.
m == grid.length
n == grid[i].length
1 <= m, n <= 300