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
function minBinary ( n ) { var digit = Array ( 10 ) . fill ( 0 ) ; var len = 0 ; while ( n > 0 ) { digit [ len ++ ] = n % 10 ; n = parseInt ( n / 10 ) ; } digit = reverse ( digit , 0 , len - 1 ) ; var ans = 0 ; for ( i = 0 ; i < len ; i ++ ) { ans = Math . max ( ans , digit [ i ] ) ; } document . write ( " " + " " + ans + " " ) ; for ( i = 1 ; i <= ans ; i ++ ) { var num = 0 ; for ( j = 0 ; j < len ; j ++ ) { if ( digit [ j ] > 0 ) { num = num * 10 + 1 ; digit [ j ] -- ; } else { num *= 10 ; } } document . write ( num + " " ) ; } } function reverse ( str , start , end ) { var temp ; while ( start <= end ) { temp = str [ start ] ; str [ start ] = str [ end ] ; str [ end ] = temp ; start ++ ; end -- ; } return str ; } var n = 564 ; minBinary ( n ) ;