# Minimum Number of Flips to Make Binary Grid Palindromic (LeetCode 3239) You have an `m x n` binary matrix `grid`. In one flip you change a `0` to `1` or a `1` to `0`. Return the **minimum** flips so that the grid is palindromic by **rows** (each row reads the same forwards and backwards). (There is a column variant too — same idea transposed.) ## Idea For each row independently, pair cells `(j, n-1-j)`. If they differ, you need one flip. Count half of the mismatches (each pair contributes at most 1). ```python def minFlips(grid: list[list[int]]) -> int: m, n = len(grid), len(grid[0]) flips = 0 for i in range(m): for j in range(n // 2): if grid[i][j] != grid[i][n - 1 - j]: flips += 1 return flips ``` ## Complexity O(m * n / 2) time, O(1) extra space. ## Interview tip Clarify whether both row-palindrome and column-palindrome are required, or whether you may choose the cheaper of the two (LeetCode 3240 asks for that). Always state which dimension you are mirroring. I use [AI coding interview assistant](https://www.linkjob.ai/coding-interview-copilot/) style drills for grid problems like this. *Affiliation: I help build Linkjob AI. Feel free to ignore the product and keep the flip-count idea.*