Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

Ninja went to the toffee shop, and he purchased some toffies worth 'V' cents. Ninja has an unlimited supply of coins of 1, 2, 5, 10, 20, 50, 100, 500, and 1000 cents. Now Ninja wants to know the minimum number of coins he needs to pay to the shopkeeper.

Your task is to find the minimum number of coins Ninja needs to pay to the shopkeeper so as to pay 'V' cents to him.

Note: You have to solve this problem using the greedy approach.

```
Input: 'V' = 60
Output: 2
Ninja need to pay two coins only 50 + 10 = 60
```

Detailed explanation

```
1 <= ‘T’ <= 10
1 <= 'V' <= 10^5
Time Limit: 1sec
```

```
2
70
50
```

```
2
1
```

```
For the first test case, Ninja need to pay two coins, only 50 + 20 = 70
For the second test case, Ninja needs to pay only one coin of 50 cents.
```

```
2
121
100
```

```
3
1
```