Stores the indices of element
Map < Integer , Integer > index = new HashMap < > ( ) ; for ( int i = 0 ; i < n ; i ++ ) index . put ( arr [ i ] , i ) ; ArrayList < Integer > boundary = new ArrayList < > ( ) ; boundary . add ( - 1 ) ; boundary . add ( n ) ; Arrays . sort ( arr ) ;