Practice/Apple/Leetcode 3000. Maximum Area of Longest Diagonal Rectangle
CodingOptional
You are given an array of rectangles where each rectangle is represented by a pair of integers [length, width]. Your task is to identify the rectangle that has the longest diagonal. If multiple rectangles share the same longest diagonal length, return the area of the one with the maximum area among them.
The diagonal of a rectangle with dimensions length and width can be computed using the Pythagorean theorem. To avoid floating-point arithmetic, compare the squared values of diagonals (length² + width²) instead of computing square roots.
Return the area (length × width) of the selected rectangle.
Example 1:
` Input: dimensions = [[9, 3], [8, 6], [4, 7]] Output: 48 Explanation:
Example 2:
Input: dimensions = [[3, 4], [4, 3]] Output: 12 Explanation: Both rectangles have diagonal² = 25 and area = 12. Since they tie on both diagonal and area, return 12.
Example 3:
` Input: dimensions = [[10, 4], [8, 7], [6, 9]] Output: 56 Explanation: