3989. Maximum Consistent Columns in a Grid
You are given a 2D integer array
gridof sizem x n, and an integerlimit.You may remove zero or more columns from the grid, but at least one column must remain. The relative order of the remaining columns must be preserved.
A grid is called consistent if for every row
i, and for every pair of adjacent remaining columnsaandbwitha < b, the following holds:|grid[i][b] - grid[i][a]| <= limit.Return the maximum number of columns that can remain such that the resulting grid is consistent.
1 | class Solution { |