Dashboard Temp Share Shortlinks Frames API

HTMLify

maximize-area-of-square-hole-in-grid.py
Views: 5 | Author: prakhardoneria
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution:
    def maximizeSquareHoleArea(self, n: int, m: int, hBars: List[int], vBars: List[int]) -> int:
        def get_max_gap(bars):
            if not bars:
                return 1
            bars.sort()
            max_consecutive = 1
            current_streak = 1
            
            for i in range(1, len(bars)):
                if bars[i] == bars[i-1] + 1:
                    current_streak += 1
                else:
                    current_streak = 1
                max_consecutive = max(max_consecutive, current_streak)
            
            return max_consecutive + 1

        max_h_gap = get_max_gap(hBars)
        max_v_gap = get_max_gap(vBars)
        
        side = min(max_h_gap, max_v_gap)
        return side * side