Case - 3 :
else if ( neg . size ( ) >= 2 ) { int negMax = INT_MIN , negMaxIdx = -1 ; int negMin = INT_MAX , negMinIdx = -1 ; for ( int i = 0 ; i < neg . size ( ) ; i ++ ) { if ( abs ( arr [ neg [ i ] ] ) > negMax ) { negMaxIdx = neg [ i ] ; negMax = abs ( arr [ negMaxIdx ] ) ; } } for ( int i = 0 ; i < neg . size ( ) ; i ++ ) { if ( abs ( arr [ neg [ i ] ] ) < negMin && neg [ i ] != negMaxIdx ) { negMinIdx = neg [ i ] ; negMin = abs ( arr [ negMinIdx ] ) ; } } res . push_back ( arr [ negMinIdx ] ) ; res . push_back ( arr [ negMaxIdx ] ) ; for ( int i = 0 ; i < n ; i ++ ) if ( i != negMinIdx && i != negMaxIdx ) res . push_back ( arr [ i ] ) ; for ( int i = 0 ; i < res . size ( ) ; i ++ ) cout << res [ i ] << " ▁ " ; cout << " STRNEWLINE " ; }