Find the non decreasing order array from given array | C # implementation of the approach ; Utility function to print the contents of the array ; Function to build array B [ ] ; Lower and upper limits ; To store the required array ; Apply greedy approach ; Print the built array b [ ] ; Driver code
using System ; public class GFG { static void printArr ( int [ ] b , int n ) { for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( " ▁ " + b [ i ] + " ▁ " ) ; } } static void ModifiedArray ( int [ ] a , int n ) { int l = 0 , r = int . MaxValue ; int [ ] b = new int [ n ] ; for ( int i = 0 ; i < n / 2 ; i ++ ) { b [ i ] = Math . Max ( l , a [ i ] - r ) ; b [ n - i - 1 ] = a [ i ] - b [ i ] ; l = b [ i ] ; r = b [ n - i - 1 ] ; } printArr ( b , n ) ; } static public void Main ( ) { int [ ] a = { 5 , 6 } ; int n = a . Length ; ModifiedArray ( a , 2 * n ) ; } }