Largest square which can be formed using given rectangular blocks | C # program for the above approach ; Function to find maximum side length of square ; Sort array in asc order ; Traverse array in desc order ; Driver code ; Given array arr [ ] ; Function Call
using System ; class GFG { static void maxSide ( int [ ] a , int n ) { int sideLength = 0 ; Array . Sort ( a ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] > sideLength ) { sideLength ++ ; } else { break ; } } Console . Write ( sideLength ) ; } public static void Main ( ) { int N = 6 ; int [ ] arr = new int [ ] { 3 , 2 , 1 , 5 , 2 , 4 } ; maxSide ( arr , N ) ; } }