human
I found an interesting problem on https://leetcode.com/problems/minimum-swaps-to-arrange-a-binary-grid/:
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:

Input: grid = [[0,0,1],[1,1,0],[1,0,0]]
Output: 3

Example 2:

Input: grid = [[0,1,1,0],[0,1,1,0],[0,1,1,0],[0,1,1,0]]
Output: -1
Explanation: All rows are similar, swaps have no effect on the grid.

Example 3:

Input: grid = [[1,0,0],[1,1,0],[1,1,1]]
Output: 0

 
Constraints:

n == grid.length
n == grid[i].length
1 <= n <= 200
grid[i][j] is 0 or 1

I tried it in Python, but could not do it. Can you solve it?

 What is a the Python code you requested?
assistant
#Here is the Python code you requested.

class Solution:
    def minSwaps(self, grid: List[List[int]]) -> int:
        def helper(row):
            for i in range(len(row) - 1, -1, -1):
                if row[i] == 1:
                    return len(row) - i - 1
            return len(row)
        arr = list(map(helper, grid))

        count = 0
        target = len(grid[0]) - 1
        for i in range(len(arr)):
            if arr[i] < target:
                found = False
                for j in range(i + 1, len(arr)):
                    if arr[j] >= target:
                        count += j - i
                        arr.insert(i, arr.pop(j))
                        found = True
                        break
                if not found:
                    return -1
            target -= 1
            
        return count