Want a Free Job Posting?

Buy a job posting today and the second one is on us. For a limited time only. Act Now.

Interview Question

Interview(Student Candidate) New York, NY

There are 3 types of coins. The values are

  1, 2, 5, respectively. What's the algorithm to get the minimun number of coins if the sum of them is N?
technical, algorithm

Interview Answer

2 Answers


dynamic programming

Interview Candidate on 2012-09-05

(function foo(n){ var coins = [1,2,5] var num = 0; while (coins.length){ var coin = coins.pop() num+= Math.floor(n/coin); n=n%coin; if(!n) break; } console.log(num); })(28)

grim face on 2012-09-07

Add Answers or Comments

To comment on this, Sign In or Sign Up.