Reorder an array such that sum of left half is not equal to sum of right half | Java program for the above approach ; 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 [ ] ; Driver code ; Given array ; Function call
import java . util . * ; class GFG { public static void printArr ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = arr . length ; printArr ( arr , N ) ; } }