3251. Maximum Area of Longest Diagonal Rectangle
My accepted C++ solution to LeetCode problem 3251, Maximum Area of Longest Diagonal Rectangle, running in 0ms.
- Difficulty: Easy
- C++
- Runtime 0ms
- Memory 29.2MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
C++
Accepted on LeetCode — runtime 0ms, memory 29.2MB, accepted 2025-12-28.
class Solution {
public:
int areaOfMaxDiagonal(vector<vector<int>>& dimensions) {
int maxDiag = 0, maxArea = 0;
for (auto& d : dimensions) {
int diag = d[0] * d[0] + d[1] * d[1];
int area = d[0] * d[1];
if (diag > maxDiag || (diag == maxDiag && area > maxArea)) {
maxDiag = diag;
maxArea = area;
}
}
return maxArea;
}
};