Find two numbers with sum N such that neither of them contains digit K | Python3 implementation of the above approach ; Count leading zeros ; It removes i characters starting from index 0 ; Check each digit of the N ; If digit is K break it ; For odd numbers ; Add D1 to A and D2 to B ; If the digit is not K , no need to break String D in A and 0 in B ; Remove leading zeros ; Print the answer ; Driver code
def removeLeadingZeros ( Str ) : NEW_LINE INDENT i = 0 NEW_LINE n = len ( Str ) NEW_LINE while ( Str [ i ] == '0' and i < n ) : NEW_LINE INDENT i += 1 NEW_LINE DEDENT Str = Str [ i : ] NEW_LINE return Str NEW_LINE DEDENT def findPairs ( Sum , K ) : NEW_LINE INDENT A = " " NEW_LINE B = " " NEW_LINE N = str ( Sum ) NEW_LINE n = len ( N ) NEW_LINE for i in range ( n ) : NEW_LINE D = int ( N [ i ] ) - int ( '0' ) NEW_LINE if ( D == K ) : NEW_LINE INDENT D1 = D // 2 ; NEW_LINE D2 = ( D // 2 ) + ( D % 2 ) NEW_LINE A = A + ( str ) ( D1 + int ( '0' ) ) NEW_LINE B = B + ( str ) ( D2 + int ( '0' ) ) NEW_LINE DEDENT else : NEW_LINE INDENT A = A + ( str ) ( D + int ( '0' ) ) NEW_LINE B = B + '0' NEW_LINE DEDENT A = removeLeadingZeros ( A ) NEW_LINE B = removeLeadingZeros ( B ) NEW_LINE print ( A + " , ▁ " + B ) NEW_LINE DEDENT N = 33673 NEW_LINE K = 3 NEW_LINE findPairs ( N , K ) NEW_LINE