You are given an n $ imes$ n binary matrix grid. In a single operation, you can choose any two adjacent rows and swap them.
The grid is considered valid if all cells situated strictly above the main diagonal are
Return the minimum number of operations needed to make grid valid, or
Note: The main diagonal consists of the cells
grid[i][j]whereij. Cells strictly above the main diagonal are those whereij.
Constraints:
n grid.length grid[i].length
n
grid[i][j] is either
You are given an n $ imes$ n binary matrix grid. In a single operation, you can choose any two adjacent rows and swap them.
The grid is considered valid if all cells situated strictly above the main diagonal are
Return the minimum number of operations needed to make grid valid, or
Note: The main diagonal consists of the cells
grid[i][j]whereij. Cells strictly above the main diagonal are those whereij.
Constraints:
n grid.length grid[i].length
n
grid[i][j] is either