Check if any valid sequence is divisible by M |  ; Base case ; check if sum is divisible by M ; 1. Try placing ' + ' ; 2. Try placing ' - '
bool isPossible ( int index , int sum ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } bool placeAdd = isPossible ( index + 1 , sum + arr [ index ] ) ; bool placeMinus = isPossible ( index + 1 , sum - arr [ index ] ) ; if ( placeAdd placeMinus ) return true ; return false ; }