Pergunta de entrevista da empresa Toptal

1. Return minimum number of coins/notes change 2. Form a string given a precedence array.

Respostas da entrevista

Sigiloso

10 de ago. de 2022

Here is my solution for the question. int totalCoins = 0; int divident = 0; if(n >= 25){ divident = n/25; totalCoins+= divident; n -= (divident * 25); } if(n >= 10){ divident = n/10; totalCoins += divident; n -= (divident*10); } if(n >= 5){ divident = n/5; totalCoins += divident; n -= (divident*5); } if(n>0) totalCoins += n; return totalCoins;

1

Sigiloso

17 de jun. de 2022

Given a value V, if we want to make a change for V cents, and we have an infinite supply of each of C = { C1, C2, .., Cm} valued coins, what is the minimum number of coins to make the change? If it’s not possible to make a change, print -1. Examples: 1. Return minimum number of coins/notes change Input: coins[] = {25, 10, 5}, V = 30 Output: Minimum 2 coins required We can use one coin of 25 cents and one of 5 cents Input: coins[] = {9, 6, 5, 1}, V = 11 Output: Minimum 2 coins required We can use one coin of 6 cents and 1 coin of 5 cents

4