a vector that store indices of the negative elements
ArrayList < Integer > neg = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos . add ( i ) ; else if ( arr [ i ] < 0 ) neg . add ( i ) ; }