Interview Question

Analyst 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?
Tags:
technical, algorithm
Answer

Interview Answer

2 Answers

0

dynamic programming

Interview Candidate on Sep 5, 2012
0

(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 Sep 7, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up