LeetCode solutions

3461. Find the Minimum Area to Cover All Ones I

My accepted Python solution to LeetCode problem 3461, Find the Minimum Area to Cover All Ones I, running in 2999ms.

  • Difficulty: Medium
  • Python
  • Runtime 2999ms
  • Memory 47.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 2999ms, memory 47.2MB, accepted 2026-01-01.

python
class Solution:
    def minimumArea(self, grid: List[List[int]]) -> int:
        rows = len(grid)
        cols = len(grid[0])
        
        min_row, max_row = rows, -1
        min_col, max_col = cols, -1
        
        for i in range(rows):
            for j in range(cols):
                if grid[i][j] == 1:
                    min_row = min(min_row, i)
                    max_row = max(max_row, i)
                    min_col = min(min_col, j)
                    max_col = max(max_col, j)
        
        return (max_row - min_row + 1) * (max_col - min_col + 1)

Source