Finding the r [ ] and l [ ] arrays .
for ( int j = 1 ; j < n ; j ++ ) { L . add ( ( 2 * freq [ j - 1 ] ) - j ) ; R . add ( ( 2 * freq [ j ] ) - j ) ; } int max_len = Integer . MIN_VALUE ; int min_val = Integer . MAX_VALUE ;