Minimum number of Binary strings to represent a Number | Function to find the minimum number of binary strings to represent a number ; Storing digits in correct order ; Find the maximum digit in the array ; Traverse for all the binary strings ; If digit at jth position is greater than 0 then substitute 1 ; Driver code
def minBinary ( n ) : NEW_LINE INDENT digit = [ 0 for i in range ( 3 ) ] NEW_LINE len = 0 NEW_LINE while ( n > 0 ) : NEW_LINE INDENT digit [ len ] = n % 10 NEW_LINE len += 1 NEW_LINE n //= 10 NEW_LINE DEDENT digit = digit [ : : - 1 ] NEW_LINE ans = 0 NEW_LINE for i in range ( len ) : NEW_LINE INDENT ans = max ( ans , digit [ i ] ) NEW_LINE DEDENT print ( " Minimum ▁ Number ▁ of ▁ binary ▁ strings ▁ needed : " , ans ) NEW_LINE for i in range ( 1 , ans + 1 , 1 ) : NEW_LINE INDENT num = 0 NEW_LINE for j in range ( 0 , len , 1 ) : NEW_LINE INDENT if ( digit [ j ] > 0 ) : NEW_LINE INDENT num = num * 10 + 1 NEW_LINE digit [ j ] -= 1 NEW_LINE DEDENT else : NEW_LINE INDENT num *= 10 NEW_LINE DEDENT DEDENT print ( num , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 564 NEW_LINE minBinary ( n ) NEW_LINE DEDENT