Rearrange an Array such that Sum of same | C # Program to implement the above approach ; Function to rearrange the array such that no same - indexed subset have sum equal to that in the original array ; Initialize a vector ; Iterate the array ; Sort the vector ; Shift of elements to the index of its next cyclic element ; Print the answer ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void printNewArray ( List < int > a , int n ) { List < Tuple < int , int > > v = new List < Tuple < int , int > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { v . Add ( new Tuple < int , int > ( a [ i ] , i ) ) ; } v . Sort ( ) ; int [ ] ans = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { ans [ v [ ( i + 1 ) % n ] . Item2 ] = v [ i ] . Item1 ; } for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( ans [ i ] + " ▁ " ) ; } } static void Main ( ) { List < int > a = new List < int > ( new int [ ] { 4 , 1 , 2 , 5 , 3 } ) ; int n = a . Count ; printNewArray ( a , n ) ; } }