aboutsummaryrefslogtreecommitdiff
path: root/max_area_longest_diag_rect.py
blob: 7789f7406c1a4685ae1a2ed31f310959627f5f25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 3000. Maximum Area of Longest Diagonal Rectangle

"""
you are given a 2d 0-indexed integer array 'dimensions'. for all indices 'i',
'0 <= i < dimensions.size', 'dimensions[i][0]' represents the length and
'dimensions[i][1]' represents the width of the rectangle 'i'. return the area
of the rectangle having the longest diagonal, return the area of the
rectangle having the maximum area.
"""


class Solution(object):
    def areaOfMaxDiagonal(self, dimensions):
        """
        :type dimensions: List[List[int]]
        :rtype: int
        """
        ans, area = 0, 0
        for l, w in dimensions:
            curr = l * l + w * w
            if curr > area or (curr == area and l * w > ans):
                area = curr
                ans = l * w
        return ans


if __name__ == "__main__":
    obj = Solution()
    print(obj.areaOfMaxDiagonal(dimensions=[[9, 3], [8, 6]]))
    print(obj.areaOfMaxDiagonal(dimensions=[[3, 4], [4, 3]]))