shlogg · Early preview
Md Ariful Haque @mah-shamim

Minimum Operations To Satisfy Grid Conditions In 2D Matrix

Minimum operations needed to satisfy conditions in grid: min number of changes to make each cell equal to below it and different from right cell, if exists.

3122. Minimum Number of Operations to Satisfy Conditions
Medium
You are given a 2D matrix grid of size m x n. In one operation, you can change the value of any cell to any non-negative number. You need to perform some operations such that each cell grid[i][j] is:

Equal to the cell below it, i.e. grid[i][j] == grid[i + 1][j] (if it exists).
Different from the cell to its right, i.e. grid[i][j] != grid[i][j + 1] (if it exists).

Return the minimum number of operations needed.
Example 1:

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


All the cells in the matrix already satisfy the pr...