Case - 1 :
if ( len ( pos ) >= 2 and len ( neg ) >= 2 ) : NEW_LINE INDENT posMax = - sys . maxsize - 1 NEW_LINE posMaxIdx = - 1 NEW_LINE posMin = sys . maxsize NEW_LINE posMinIdx = - 1 NEW_LINE negMax = - sys . maxsize - 1 NEW_LINE negMaxIdx = - 1 NEW_LINE negMin = sys . maxsize NEW_LINE negMinIdx = - 1 NEW_LINE for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] > posMax ) : NEW_LINE INDENT posMaxIdx = pos [ i ] NEW_LINE posMax = arr [ posMaxIdx ] NEW_LINE DEDENT DEDENT for i in range ( len ( pos ) ) : NEW_LINE INDENT if ( arr [ pos [ i ] ] < posMin and pos [ i ] != posMaxIdx ) : NEW_LINE INDENT posMinIdx = pos [ i ] NEW_LINE posMin = arr [ posMinIdx ] NEW_LINE DEDENT DEDENT for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) > negMax ) : NEW_LINE INDENT negMaxIdx = neg [ i ] NEW_LINE negMax = abs ( arr [ negMaxIdx ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( neg ) ) : NEW_LINE INDENT if ( abs ( arr [ neg [ i ] ] ) < negMin and neg [ i ] != negMaxIdx ) : NEW_LINE INDENT negMinIdx = neg [ i ] NEW_LINE negMin = abs ( arr [ negMinIdx ] ) NEW_LINE DEDENT DEDENT posVal = ( - 1.0 * posMax / posMin ) NEW_LINE negVal = ( - 1.0 * negMax / negMin ) NEW_LINE if ( posVal < negVal ) : NEW_LINE INDENT res . append ( arr [ posMinIdx ] ) NEW_LINE res . append ( arr [ posMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != posMinIdx and i != posMaxIdx ) : NEW_LINE INDENT res . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT else : NEW_LINE INDENT res . append ( arr [ negMinIdx ] ) NEW_LINE res . append ( arr [ negMaxIdx ] ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( i != negMinIdx and i != negMaxIdx ) : NEW_LINE INDENT resal . append ( arr [ i ] ) NEW_LINE DEDENT DEDENT DEDENT for i in range ( len ( res ) ) : NEW_LINE INDENT print ( res [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT