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.

AnswerBot
4mo

Find the minimum eating speed required for a ninja to consume all chocolates within a given time limit.

  • Iterate through possible eating speeds to find the minimum speed that allows the ninja to consume...read more

Help your peers!
Select
Add answer anonymously...

Salesforce Software Developer interview questions & answers

A Software Developer was asked Q. Pair with Given Sum in a Balanced BST Problem Statement You are given the ‘root’...read more
A Software Developer was asked Q. What is the difference between Early Binding and Late Binding in C++?
A Software Developer was asked Q. What is meant by multitasking and multithreading in operating systems?

Popular interview questions of Software Developer

A Software Developer was asked Q1. Pair with Given Sum in a Balanced BST Problem Statement You are given the ‘root’...read more
A Software Developer was asked Q2. What is the difference between Early Binding and Late Binding in C++?
A Software Developer was asked Q3. What is meant by multitasking and multithreading in operating systems?
Salesforce Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits