Welcome!

×

...or use your e-mail

Go back to Challenges list

Challenge

Vending Machine

In this challenge you will need to develop the algorithm for a vending machine your company is creating.

You will have a fixed list of products:
Code Name Price
A01 Cookies 0.85€
A02 Coffe 0.35€
A03 Water 0.55€
A04 Sandwich 2.5€
A05 Microwave Meal 6.85€

Every time a person uses the vending machine, your algorithm will receive the code of the product the person selected, the quantity of each coins and/or notes that the person introduced and the quantity of coins and notes the vending machine has available at that point. With this information you will need to output the coins and/or notes used to give the change to that person, having in mind that you should use the minimum quantity of coins and/or notes possible.
You will not need to worry about the quantity of products available in the machine but you will need to validate the code of the product inserted by the person. If the code does not exist output "Wrong code".
You also need to validate if there are coins and/or notes available to give the correct change, if not you need to output "No coins".
If the person introduced the exact amount for the purchase, the output should be "No change".
If the person introduced less money that is necessary, the output should be "Not enough money".

To simplify the output each coin and note has a code:
Code Type Value
0 Coin 0.05€
1 Coin 0.10€
2 Coin 0.20€
3 Coin 0.50€
4 Coin 1€
5 Coin 2€
6 Note 5€
7 Note 10€
8 Note 20€


Input Format
Each input will be a JSON object with the product code, the quantities, by order, of the inserted coins/notes and the existing coins/notes on the vending machine:
{"product_code": "A01", "inserted_money": [ 0, 0, 0, 0, 0, 0, 1, 0, 0 ], "existing_money": [ 5, 10, 2, 12, 2, 2, 1, 3, 0 ]}


Output Format
The output should be the code of the coins/notes, separated by spaces, used in the change. If the same coin/note was used more then once, her code should appear that exact number of times. The codes should be ordered ascending.

Sample Input
{"product_code":"A01","inserted_money":[0,0,0,0,0,0,1,0,0],"existing_money":[5,10,2,12,2,2,1,3,0]}

Sample Output
0 1 5 5

Memory Limit
512M


Sign Up or Login to solve this Code Challenge