Digitally balanced numbers | Function to check if the digits in the number is the same number of digits ; Loop to iterate over the digits of the number N ; Loop to iterate over the map ; Driver code ; Function to check
def checkSame ( n , b ) : NEW_LINE INDENT m = { } NEW_LINE while ( n != 0 ) : NEW_LINE INDENT r = n % b NEW_LINE n = n // b NEW_LINE if r in m : NEW_LINE INDENT m [ r ] += 1 NEW_LINE DEDENT else : NEW_LINE INDENT m [ r ] = 1 NEW_LINE DEDENT DEDENT last = - 1 NEW_LINE for i in m : NEW_LINE INDENT if last != - 1 and m [ i ] != last : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT last = m [ i ] NEW_LINE DEDENT DEDENT return True NEW_LINE DEDENT n = 9 NEW_LINE base = 2 NEW_LINE if ( checkSame ( n , base ) ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT