Maximum area rectangle by picking four sides from array | c # program for finding maximum area possible of a rectangle ; function for finding max area ; traverse through array ; If this is first occurrence of arr [ i ] , simply insert and continue ; If this is second ( or more ) occurrence , update first and second maximum values . ; return the product of dimensions ; driver function
using System ; using System . Collections . Generic ; public class GFG { public static int findArea ( int [ ] arr , int n ) { ISet < int > s = new HashSet < int > ( ) ; int first = 0 , second = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! s . Contains ( arr [ i ] ) ) { s . Add ( arr [ i ] ) ; continue ; } if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) { second = arr [ i ] ; } } return ( first * second ) ; } public static void Main ( string [ ] args ) { int [ ] arr = new int [ ] { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = arr . Length ; Console . WriteLine ( findArea ( arr , n ) ) ; } }