Kevin and his Fruits Problem Statement

Kevin has 'N' buckets, each consisting of a certain number of fruits. Kevin wants to eat at least 'M' fruits. He is looking to set a marker as high as possible such that if he eats the number of fruits in the i-th bucket minus the marker, the total must be at least 'M'.

Input:

The input begins with a single integer 'T', the number of test cases.
Each test case consists of:
- Two space-separated integers 'N' (number of buckets) and 'M' (minimum fruits to eat).
- A second line with 'N' space-separated integers indicating the number of fruits in each bucket.

Output:

For each test case, print the marker value needed, with each output on a new line.

Example:

Input:
1
4 30
10 40 30 20
Output:
20

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 104
  • 1 <= M <= 106
  • 0 <= ARR[i] <= 104

Note:

It is guaranteed that the total number of fruits in all buckets is greater than 'M'. Kevin can only eat fruits from a bucket if the bucket has more fruits than the marker.

AnswerBot
4mo

Find the marker value needed for Kevin to eat at least 'M' fruits from 'N' buckets.

  • Iterate through each test case and calculate the marker value needed based on the number of fruits in each bucket.

  • Sub...read more

Devendra Badgujar
4mo
10 20 10
Help your peers!
Select
Add answer anonymously...

Apple Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Kevin and his Fruits Problem Statement Kevin has 'N' buckets, each consisting of...read more
A Software Developer Intern was asked Q. Max GCD Pair Problem Statement Given an array of positive integers, determine th...read more
A Software Developer Intern was asked Q. Lazy Santa Problem Statement It's Christmas and Santa has 'K' gifts to distribut...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Kevin and his Fruits Problem Statement Kevin has 'N' buckets, each consisting of...read more
A Software Developer Intern was asked Q2. Max GCD Pair Problem Statement Given an array of positive integers, determine th...read more
A Software Developer Intern was asked Q3. Lazy Santa Problem Statement It's Christmas and Santa has 'K' gifts to distribut...read more
Apple Software Developer Intern 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