Check if sum of array can be made equal to X by removing either the first or last digits of every array element | Utility Function to check if the sum of the array elements can be made equal to X by removing either the first or last digits of every array element ; Base Case ; Convert arr [ i ] to string ; Remove last digit ; Remove first digit ; Recursive function call ; Function to check if sum of given array can be made equal to X or not ; Driver Code ; Function Call
def makeSumX ( arr , X , S , i ) : NEW_LINE INDENT if i == len ( arr ) : NEW_LINE INDENT return S == X NEW_LINE DEDENT a = str ( arr [ i ] ) NEW_LINE l = int ( a [ : - 1 ] ) NEW_LINE r = int ( a [ 1 : ] ) NEW_LINE x = makeSumX ( arr , X , S + l , i + 1 ) NEW_LINE y = makeSumX ( arr , X , S + r , i + 1 ) NEW_LINE return x | y NEW_LINE DEDENT def Check ( arr , X ) : NEW_LINE INDENT if ( makeSumX ( arr , X , 0 , 0 ) ) : NEW_LINE print ( " Yes " ) NEW_LINE else : NEW_LINE print ( " No " ) NEW_LINE DEDENT arr = [ 545 , 433 , 654 , 23 ] NEW_LINE X = 134 NEW_LINE Check ( arr , X ) NEW_LINE