Pergunta de entrevista da empresa Google

Given US denomination coins, what is the algorithm to make change for any amount?

Respostas da entrevista

Sigiloso

2 de mar. de 2012

Code is in JAVA : public class USCoins { public static void main(String args[]) { int[] coinDenominations = {25,10,5,1}; double totalAmountInDollars = 3.46; int[] numberOfEachCoin = getNumber(coinDenominations,totalAmountInDollars); for(int number : numberOfEachCoin) System.out.println(number); } private static int[] getNumber(int[] coinDenominations, double totalAmountInDollars) { int numberOfEachCoin[] = new int[coinDenominations.length]; int totalAmountInCents = (int) (totalAmountInDollars*100); for(int i=0;i

3

Sigiloso

19 de mar. de 2012

Inspired by this problem, I have proposed a solution that print out all possible change combinations per given amount. I demo the problem solving process in this video: http://www.youtube.com/watch?v=3VBjhiKUtmE

Sigiloso

29 de fev. de 2012

Greedy algorithm will work in this case