Minimum Umbrellas Problem

You are provided with ‘N’ types of umbrellas, where each umbrella type can shelter a certain number of people. Given an array UMBRELLA that indicates the number of people each umbrella can cover, determine the minimum number of umbrellas required to shelter exactly ‘M’ people.

Input:

T
N M
UMBRELLA

Output:

Minimum number of umbrellas or -1

Example:

Input:
2
3 5
2 3 4
4 7
1 3 5 6
Output:
2
2
Explanation:

In the first test case, using one 2-capacity umbrella and one 3-capacity umbrella gives a total of 5 people covered. In the second test case, using one 6-capacity umbrella and one 1-capacity umbrella covers exactly 7 people.

Constraints:

  • 1 ≤ T ≤ 5
  • 1 ≤ N ≤ 103
  • 1 ≤ UMBRELLA[i] ≤ 109
  • 1 ≤ M ≤ 103
Note:

If it is not feasible to cover ‘M’ people exactly, print -1.

Ensure you implement the function provided and do not handle input/output operations directly.

AnswerBot
4mo

Given 'N' types of umbrellas with different capacities, find the minimum number of umbrellas required to shelter exactly 'M' people.

  • Iterate through the umbrella capacities and try to cover 'M' people ...read more

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