Minimum number of coins that can generate all the values in the given range | Function to return the count of minimum coins required ; To store the required sequence ; Creating list of the sum of all previous bit values including that bit value ; Driver Code
function findCount ( N ) { let list = [ ] ; let sum = 0 ; let i ; for ( i = 0 ; i < 20 ; i ++ ) { sum += parseInt ( Math . pow ( 2 , i ) , 10 ) ; list . push ( sum ) ; } for ( i = 0 ; i < 20 ; i ++ ) { if ( list [ i ] >= N ) return ( i + 1 ) ; } return 0 ; } let N = 10 ; document . write ( findCount ( N ) ) ;