Rectangle with Maximum Area using Java Pair Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice Given an array of pairs containing length and breadth of rectangles. The task is to find the maximum area of the rectangle. Examples: Input: (1, 2), (3, 5), (1, 1), (4, 2) Output: 15 Input: (3, 5), (5, 5), (9, 10) Output: 90Recommended PracticeMaximum Area RectangleTry It! Approach: Use user defined Pair class to store Breadth and Height of rectangles.Make an array of this class.Now, traverse the array and find the area each time. Also, keep track of maximum area.Return the maximum area of rectangle. Java // Java code to find maximum Area import java.io.*; import java.util.*; // Pair class class Rectangle { // length and int length; int breadth; // Rectangle Constructor public Rectangle(int x, int y) { this.length = x; this.breadth = y; } } // Class Area to calculate Area of rectangles class Area { // Function to calculate area static int calculate_Area(Rectangle arr[]) { int max_Area = Integer.MIN_VALUE; // loop to iterate through all rectangles // and keep track of max area for (int i = 0; i < arr.length; i++) { int temp_area = arr[i].length * arr[i].breadth; if (temp_area > max_Area) { max_Area = temp_area; } } return max_Area; } } // Driver class with main function class GFG { // Driver code public static void main(String[] args) { Scanner sc = new Scanner(System.in); // Creating an array of Pair Rectangle arr[] = new Rectangle[3]; int x = 10, y = 20; arr[0] = new Rectangle(x, y); x = 5; y = 25; arr[1] = new Rectangle(x, y); x = 15; y = 10; arr[1] = new Rectangle(x, y); x = 12; y = 12; arr[2] = new Rectangle(x, y); Area obj = new Area(); System.out.println(obj.calculate_Area(arr)); } } Output:200 Time complexity: O(n) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Maximum area of rectangle possible with given perimeter B barykrg Follow Improve Article Tags : Java area-volume-programs Practice Tags : Java Similar Reads Maximum area of rectangle possible with given perimeter Given the perimeter of a rectangle, the task is to find the maximum area of a rectangle which can use n-unit length as its perimeter. Note: Length and Breadth must be an integral value. Example: Input: perimeter = 15 Output: Maximum Area = 12 Input: perimeter = 16 Output: Maximum Area = 16 Approach: 3 min read Maximum area rectangle by picking four sides from array Given an array arr[] of positive integers representing lengths, the task is to find the maximum possible rectangular area that can be formed using four sides from the array. Note: A valid rectangle requires at least two pairs of equal values. If no such rectangle is possible, return 0.Examples: Inpu 9 min read Java Program for Maximum sum rectangle in a 2D matrix | DP-27 Write a Java program for a given 2D array, the task is to find the maximum sum subarray in it. For example, in the following 2D array, the maximum sum subarray is highlighted with blue rectangle and sum of this subarray is 29. This problem is mainly an extension of the Largest Sum Contiguous Subarra 5 min read Area of the largest Rectangle without a given point Given the length L and breadth B of a rectangle and the position of a hole in the rectangle as (X, Y) coordinate, the task is to find the area of largest Rectangle within the given Rectangle such that it does not contain the hole.Note: The rectangle is placed at the origin by two of its side touchin 6 min read Minimum area of square holding two identical rectangles Given the length L and breadth B of two identical rectangles, the task is to find the minimum area of a square in which the two identical rectangles with dimensions L Ã B can be embedded.Examples: Input: L = 7, B = 4 Output: 64 Explanation: Two rectangles with sides 7 x 4 can fit into square with si 4 min read Java Program for Maximum height when coins are arranged in a triangle We have N coins which need to arrange in form of a triangle, i.e. first row will have 1 coin, second row will have 2 coins and so on, we need to tell maximum height which we can achieve by using these N coins. Examples: Input : N = 7 Output : 3 Maximum height will be 3, putting 1, 2 and then 3 coins 2 min read Like