Morgan Stanley Interview Question: There are 3 types of coins. T... | Glassdoor

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?
technical, algorithm

Interview Answer

2 Answers


dynamic programming

Interview Candidate on Sep 5, 2012

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

grim face on Sep 7, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.