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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxSide ( int a [ ] , int n ) { int sideLength = 0 ; sort ( a , a + n ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( a [ i ] > sideLength ) { sideLength ++ ; } else { break ; } } cout << sideLength << endl ; } int main ( ) { int N = 6 ; int arr [ ] = { 3 , 2 , 1 , 5 , 2 , 4 } ; maxSide ( arr , N ) ; return 0 ; }