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
def factorsOf3 ( arr , N ) : NEW_LINE INDENT a = 0 NEW_LINE b = 0 NEW_LINE c = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] % 3 == 0 ) : NEW_LINE INDENT a += 1 NEW_LINE DEDENT elif ( arr [ i ] % 3 == 1 ) : NEW_LINE INDENT b += 1 NEW_LINE DEDENT elif ( arr [ i ] % 3 == 2 ) : NEW_LINE INDENT c += 1 NEW_LINE DEDENT DEDENT if ( a >= 1 and a <= b + c + 1 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT elif ( a == 0 and b == 0 and c > 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT elif ( a == 0 and c == 0 and b > 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT arr = [ 1 , 2 , 3 , 3 ] NEW_LINE N = len ( arr ) NEW_LINE factorsOf3 ( arr , N ) NEW_LINE