


The first line of input contains an integer 'T' representing the number of test cases. Then the test cases follow.
The first line of each test case contains a positive integer P, representing the total amount.
For each test case, print the minimum number of coins that sums to P.
The output for each test case is in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= P <= 10^9
Time Limit: 1 sec
We will recursively find the minimum number of coins.
Algorithm:
Let’s say we have a recursive function ‘minimumCoinsHelper’ which will return the minimum number of coins that sums to amount P.
In the previous approach, we are recalculating the answer for an amount. We can optimise it by storing the answer for the amount which we have calculated.
For example, if P=5 :
We are recalculating the answer for P = 3, 2 and 1.
So since there are overlapping solutions, we can use Dynamic Programming.
Let’s make an array DP of size P+1, where DP[i] denotes the minimum number of coins that sums to amount ‘i’.
DP[0] = 0, because 0 coins are needed for 0 amount.
Initialise all other values with a maximum value (INT_MAX).
Now, iterate on the amount from 0 to P-1
DP[P] stores the minimum number of coins that sums to P.
We will greedily solve this problem by finding the number of coins we can take with the largest denomination and then with the next largest denomination and so on until the total amount becomes zero.
Algorithm: