Dashboard Temp Share Shortlinks Frames API

HTMLify

find-the-largest-area-of-square-inside-two-rectangle.py
Views: 2 | Author: prakhardoneria
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class Solution:
    def largestSquareArea(self, bottomLeft: List[List[int]], topRight: List[List[int]]) -> int:
        max_side = 0
        n = len(bottomLeft)
        
        for i in range(n):
            for j in range(i + 1, n):
                x_start = max(bottomLeft[i][0], bottomLeft[j][0])
                y_start = max(bottomLeft[i][1], bottomLeft[j][1])
                x_end = min(topRight[i][0], topRight[j][0])
                y_end = min(topRight[i][1], topRight[j][1])
                
                width = x_end - x_start
                height = y_end - y_start
                
                if width > 0 and height > 0:
                    side = min(width, height)
                    max_side = max(max_side, side)
                    
        return max_side * max_side