Stores the indices of element
Dictionary < int , int > index = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) index [ arr [ i ] ] = i ; ArrayList boundary = new ArrayList ( ) ; boundary . Add ( - 1 ) ; boundary . Add ( n ) ; Array . Sort ( arr ) ;