Reorder an array such that sum of left half is not equal to sum of right half | Function to print the required reordering of array if possible ; Sort the array in increasing order ; If all elements are equal , then it is not possible ; Else print the sorted array arr ; Given array ; Function call
function printArr ( arr , n ) { arr . sort ( ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { document . write ( " " ) ; } else { document . write ( " " ) ; for ( i = 0 ; i < n ; i ++ ) { document . write ( arr [ i ] + " " ) ; } } } var arr = [ 1 , 2 , 2 , 1 , 3 , 1 ] ; var N = arr . length ; printArr ( arr , N ) ;