Function to find the max size possible
static int findMaxSize ( int a [ ] , int n ) { ArrayList < Integer > frq = new ArrayList < Integer > ( n + 1 ) ; for ( int i = 0 ; i <= n ; i ++ ) frq . add ( 0 ) ; for ( int i = 0 ; i < n ; ++ i ) frq . set ( a [ i ] , frq . get ( a [ i ] ) + 1 ) ;