Determine whether a small grid satisfies a set of local cell-by-cell constraints.
Given an grid of integers, check whether it satisfies a set of local conditions involving each cell and its neighboring cells.
In this problem, you inspect the grid directly and verify that every required condition holds. The task is primarily about careful iteration over the matrix and correctly handling boundaries when comparing neighboring values.
Return whether the grid satisfies all conditions.
Input Format
- An integer grid with rows and columns.
- Each cell contains an integer value.
- The exact validity rule is determined by the problem statement for each cell and its adjacent cells.
Output Format
- Return
trueif the grid satisfies all required conditions. - Otherwise, return
false.
Constraints
- The grid size is finite and small enough for direct iteration.
- Values are integers.
- Boundary cells must be handled safely when checking neighbors.
Example 1
Input
grid = [[1,0,1],[1,1,0]]
Output
true
Explanation
All cells satisfy the required local checks for this example grid.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.