Maximum Area of Longest Diagonal Rectangle

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.
I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.
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.
LeetCode Problem: Link | Click Here
class Solution {
public int areaOfMaxDiagonal(int[][] dimensions) {
// ArrayLists to store all computed diagonal lengths and their corresponding areas
ArrayList<Double> allDiagonal = new ArrayList<>();
ArrayList<Integer> areas = new ArrayList<>();
// Variable to track the largest diagonal length found
double checkDiagonal = Double.MIN_VALUE;
// Variable to store the maximum area for the largest diagonal
int maxArea = 0;
// Loop through the given dimensions
for (int i = 0; i < dimensions.length; i++) {
int length = dimensions[i][0]; // Fetch length
int width = dimensions[i][1]; // Fetch width
int area = length * width; // Calculate area
double diagonal = Math.sqrt((length * length) + (width * width)); // Calculate diagonal length
// Store the calculated area and diagonal length
areas.add(area);
allDiagonal.add(diagonal);
// Update the maximum area if a larger diagonal is found
if (diagonal > checkDiagonal) {
checkDiagonal = diagonal;
maxArea = area;
}
}
// Find the maximum area for the largest diagonal
for (int i = 0; i < allDiagonal.size(); i++) {
if (allDiagonal.get(i) == checkDiagonal && areas.get(i) > maxArea) {
maxArea = areas.get(i);
}
}
// Return the maximum area for the largest diagonal
return maxArea;
}
}




