Maximum Area of Longest Diagonal Rectangle - Problem
You are given a 2D 0-indexed integer array dimensions. For all indices i, 0 <= i < dimensions.length, 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. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the maximum area.
Input & Output
Example 1 — Basic Case
$
Input:
dimensions = [[9,5],[4,6]]
›
Output:
45
💡 Note:
Rectangle 1: diagonal = √(9² + 5²) = √106 ≈ 10.3, area = 45. Rectangle 2: diagonal = √(4² + 6²) = √52 ≈ 7.2, area = 24. Rectangle 1 has the longest diagonal, so return its area 45.
Example 2 — Tie in Diagonal
$
Input:
dimensions = [[3,4],[4,3],[5,0]]
›
Output:
12
💡 Note:
Rectangle 1: diagonal = √(3² + 4²) = 5, area = 12. Rectangle 2: diagonal = √(4² + 3²) = 5, area = 12. Rectangle 3: diagonal = √(5² + 0²) = 5, area = 0. All have same diagonal (5), so return maximum area which is 12.
Example 3 — Single Rectangle
$
Input:
dimensions = [[6,8]]
›
Output:
48
💡 Note:
Only one rectangle with diagonal = √(6² + 8²) = 10 and area = 48. Return 48.
Constraints
- 1 ≤ dimensions.length ≤ 100
- dimensions[i].length == 2
- 1 ≤ dimensions[i][0], dimensions[i][1] ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code