Maximum area rectangle by picking four sides from array | C # program for finding maximum area possible of a rectangle ; function for finding max area ; sort array in non - increasing order ; Initialize two sides of rectangle ; traverse through array ; if any element occurs twice store that as dimension ; return the product of dimensions ; Driver Code
using System ; using System . Collections ; class GFG { static int findArea ( int [ ] arr , int n ) { Array . Sort ( arr ) ; Array . Reverse ( arr ) ; int [ ] dimension = { 0 , 0 } ; for ( int i = 0 , j = 0 ; i < n - 1 && j < 2 ; i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ; return ( dimension [ 0 ] * dimension [ 1 ] ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = arr . Length ; Console . Write ( findArea ( arr , n ) ) ; } }