Check if any valid sequence is divisible by M |  ; Base case ; check if sum is divisible by M ; 1. Try placing '+ ; 2. Try placing '-
def isPossible ( index , sum ) : NEW_LINE INDENT if ( index == n ) : NEW_LINE INDENT if ( ( sum % M ) == 0 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT DEDENT ' NEW_LINE INDENT placeAdd = isPossible ( index + 1 , sum + arr [ index ] ) ; NEW_LINE DEDENT ' NEW_LINE INDENT placeMinus = isPossible ( index + 1 , sum - arr [ index ] ) ; NEW_LINE if ( placeAdd or placeMinus ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT