1536. Minimum Swaps to Arrange a Binary Grid
https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid
Description
Given an n x n binary grid, in one step you can choose two adjacent rows of the grid and swap them.
A grid is said to be valid if all the cells above the main diagonal are zeros.
Return the minimum number of steps needed to make the grid valid, or -1 if the grid cannot be valid.
The main diagonal of a grid is the diagonal that starts at cell (1, 1) and ends at cell (n, n).
Example 1:

Example 2:

Example 3:

Constraints:
n == grid.lengthn == grid[i].length1 <= n <= 200grid[i][j]is0or1
ac
Last updated
Was this helpful?