LeetCode solutions

3415. Check if Grid Satisfies Conditions

My accepted Python solution to LeetCode problem 3415, Check if Grid Satisfies Conditions, running in 3ms.

  • Difficulty: Easy
  • Python
  • Runtime 3ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 3ms, memory 17.2MB, accepted 2026-01-01.

python
class Solution:
    def satisfiesConditions(self, grid: List[List[int]]) -> bool:
        m, n = len(grid), len(grid[0])
        for i in range(m):
            for j in range(n):
                # Check cell below
                if i + 1 < m and grid[i][j] != grid[i + 1][j]:
                    return False
                # Check cell to right
                if j + 1 < n and grid[i][j] == grid[i][j + 1]:
                    return False
        return True

Source