Check if any permutation of array contains sum of every adjacent pair not divisible by 3 | C # program for the above approach ; Function to checks if any permutation of the array exists whose sum of adjacent pairs is not divisible by 3 ; Count remainder 0 ; Count remainder 1 ; Count remainder 2 ; Condition for valid arrangements ; Driver Code ; Given array [ ] arr ; Function Call
using System ; class GFG { static void factorsOf3 ( int [ ] arr , int N ) { int a = 0 , b = 0 , c = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 3 == 0 ) a ++ ; else if ( arr [ i ] % 3 == 1 ) b ++ ; else if ( arr [ i ] % 3 == 2 ) c ++ ; } if ( a >= 1 && a <= b + c + 1 ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else if ( a == 0 && b == 0 && c > 0 ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else if ( a == 0 && c == 0 && b > 0 ) Console . Write ( " Yes " + " STRNEWLINE " ) ; else Console . Write ( " No " + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 3 } ; int N = arr . Length ; factorsOf3 ( arr , N ) ; } }