Ninja and Chocolates Problem Statement

Ninja is hungry and wants to eat his favorite chocolates, but his mother won't let him because he has already eaten enough. There are 'N' jars filled with chocolates. His mother has gone to the market and will return after 'M' minutes. The ninja can eat up to 'X' chocolates per minute. Each minute, he picks any jar and eats 'X' chocolates from it. If a jar has less than 'X', he consumes all chocolates available in that jar for that minute and stops eating more during that minute. Your goal is to determine 'X', the minimum eating speed to consume all chocolates within 'M' minutes, before his mother returns.

Input:

The first line contains an integer 'T' indicating the number of test cases.
Each test case consists of:
- The first line: two space-separated integers 'N' and 'M' (number of jars and minutes until the mother returns).
- The second line: 'N' space-separated integers representing the number of chocolates in each jar.

Output:

For each test case, output a single integer 'X', the minimum chocolate-eating speed required. Output results for each test case on a new line.

Example:

Input:

2
3 5
4 3 7
5 6
3 2 1 9 5

Output:

4
5

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 10^6
  • N ≤ M ≤ 10^9
  • 1 ≤ chocolates[i] ≤ 10^9
  • Time limit: 1 second

Note:

You do not need to print anything yourself; simply implement the required function.

Be the first one to answer
Add answer anonymously...
Salesforce Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter