Check if all array elements can be reduced to 0 by repeatedly reducing pairs of consecutive elements by their minimum | C # program to implement the above approach ; Function to check if it is possible to convert the array ; Traverse the array range [ 1 , N - 1 ] ; If arr [ i ] < arr [ i - 1 ] ; Otherwise ; Decrement arr [ i ] by arr [ i - 1 ] ; If arr [ n - 1 ] is not equal to zero ; Otherwise ; Driver Code ; Function Call
using System ; class GFG { static void checkPossible ( int [ ] arr , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < arr [ i - 1 ] ) { Console . Write ( " No STRNEWLINE " ) ; return ; } else { arr [ i ] -= arr [ i - 1 ] ; arr [ i - 1 ] = 0 ; } } if ( arr [ n - 1 ] == 0 ) { Console . Write ( " Yes STRNEWLINE " ) ; } else { Console . Write ( " No STRNEWLINE " ) ; } } public static void Main ( ) { int [ ] arr = { 2 , 3 , 3 , 4 , 2 } ; int N = arr . Length ; checkPossible ( arr , N ) ; } }