Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.51 KB

_3195. Find the Minimum Area to Cover All Ones I.md

File metadata and controls

59 lines (42 loc) · 1.51 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Completed during Weekly Contest 403 (q2)

Back to top


First completed : July 07, 2024

Last updated : July 07, 2024


Related Topics : Array, Matrix

Acceptance Rate : 73.0 %


Solutions

Python

class Solution:
    def minimumArea(self, grid: List[List[int]]) -> int:
        for r in grid :
            print(r)

        rowMin, rowMax = inf, -inf
        colMin, colMax = inf, -inf

        found = False

        for r in range(len(grid)) :
            for c in range(len(grid[0])) :
                if grid[r][c] :
                    # print(f'{r, c = }')
                    found = True
                    if r < rowMin :
                        rowMin = r
                    if r > rowMax :
                        rowMax = r
                    
                    if c < colMin :
                        colMin = c
                    if c > colMax :
                        colMax = c

        if not found :
            return 0
            
        return max((colMax - colMin + 1), 1) * max((rowMax - rowMin + 1), 1)