Problem of the day
Ninja is a lemonade seller, and all the lemonade costs 5 rupees for each product. The amount paid by each customer will be 5, 10, or 20 rupees.
You are given an array ‘bill’ of length ‘N’, where ‘bill[i]’ represents the amount paid by the ‘i’th customer. You must return the extra amount to the customers in the order they appear in the bill.
Given the array ‘bill’, you must return whether or not Ninja can return the correct change to all the customers.
Input:
bill = [5, 5, 5, 10, 10, 20], N = 6
Output:
true
Explanation: We collected 5 rupees each from the first, second, and third customers. For the fourth and fifth customers, we can return one 5 rupees coin to each. For the sixth customer, we can return one 5 rupees coin and one 10 rupees coin.
Hence we return true.
The first line of the input will contain an integer ‘N’ denoting the length of the array ‘bill’.
The next line contains ‘N’ space-separated integers.
Output prints 'true' (without quotes) if Ninja can return the correct change to all the customers. Else prints 'false'.
You don’t need to print anything. Just implement the given function.
8
5 5 5 5 10 10 20 20
true
For test case one:
Input:
bill = [5, 5, 5, 5, 10, 10, 20, 20], N=8
Output:
true
Explanation: We collected 5 rupees from the first, second, third, and fourth customers. For the fifth and sixth customers, we can return them one 5 rupees coin. For the seventh and eighth customers, we can return one 5 rupees coin and one 10 rupees coin each.
Hence we return ‘true’.
7
5 10 5 10 5 20 20
false
1 <= N <= 10^5
’bill[i]’ is 5, 10, or 20.
Time Limit: 1 sec