Check if any permutation of array contains sum of every adjacent pair not divisible by 3 | 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 ; Given array arr [ ] ; Function Call
function factorsOf3 ( arr , N ) { let a = 0 , b = 0 , c = 0 ; for ( let 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 ) document . write ( " " + " " ) ; else if ( a == 0 && b == 0 && c > 0 ) document . write ( " " + " " ) ; else if ( a == 0 && c == 0 && b > 0 ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ; } let arr = [ 1 , 2 , 3 , 3 ] ; let N = arr . length ; factorsOf3 ( arr , N ) ;