Cover image for Morgan Stanley
Logo

Morgan Stanley

Engaged employer

Morgan Stanley

Add an Interview

Interview Question

Analyst Interview

-

Morgan Stanley

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

Interview Answers

2 Answers

0

dynamic programming

Anonymous on

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

Add Answers or Comments

To comment on this, Sign In or Sign Up.