Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5761 |

@blackshadows | 5701 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 938 |

@bt8816103042 | 739 |

@SHOAIBVIJAPURE | 428 |

@codeantik | 412 |

@SherlockHolmes3 | 407 |

@neverevergiveup | 348 |

@mahlawatep | 347 |

@shalinibhataniya1097 | 343 |

@murarry3625 | 333 |

@saiujwal13083 | 326 |

@rohitanand | 314 |

Complete Leaderboard |

An employee's wallet can contain no more than **M **notes or coins. A boss pays his salary by the minimum notes possible. However the employee may have to leave out some money. Find how much money he has to lose if his original salary is **N**.

**Note**: The values of notes or coins available are 1000, 500, 100, 50, 20, 10, 5, 2 and 1.

**Example 1:**

Input:N =1712,M= 4Output:12Explanation:The boss will give him one 1000, one 500 and two 100 notes, one note of 10 and one of 2. But because the employee can't have more notes than 4, he can have a maximum amount of 1700. So, he will lose 12.

**Example 2:**

Input:N =1023,M= 2Output:3Explanation:The boss will give him one 1000, one 20 one 2 and one note of 1. But because the employee can't have more notes than 2, he can have a maximum amount of 1020. So, he will lose 3.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **getLoss()** which takes 2 Integers N and M as input and returns the answer.

**Expected Time Complexity:** O(1)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N,M <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Minimum Notes Required

...