Cash Register. Need help understanding the challenge

Hello.

This is the first time I write for help. I’m sure the answer is obvious but I can’t see it for myself.
My doubt is not about coding or how to solve the challenge. I’m sure I’ll manage to do that by myself once I understand the problem. Here is a test case for this challenge and the expected output:

checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]) should return {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]} .

My question is… why does it has to be this exact combination of currencies and amounts? There are many ways to get to change due (96.74) other than this one. For example,

{status: "OPEN", change: [["TWENTY", 80], ["TEN", 10], ["FIVE", 5], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]} .

What am I missing? Once again, I’m sure the answer is obvious and it is probably stated on the challenge’s instructions but I can’t seem to find it by myself.

Thanks for your help and your time. Once I get it should be able to beat this challenge.

1 Like

Sure, there are all sorts of ways of combining to the change due. But generally, the mechanism to give the smallest number of units is by giving as many as possible of the larger ones, then working down.

The reason for this exact combination is, the logic is structured to give as many as possible of the larger units first. That’s a pretty broad hint as to how you’ll be processing the cid array, by the way. :wink:

also, you don’t have enough TWENTY in the register to give 80$ with it, be sure to consider the cash in register!

1 Like

Oh, that’s it!
I did not realize I had only 60 for TWENTY bills… same applies for TEN and FIVE units.
Thank you, my friend. It was right in front of me :sweat_smile:

1 Like