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

The problem involves determining the minimum number of umbrellas required to shelter a specific number of people based on the capacity of each umbrella.

  • Iterate through the array of umbrella capacities...read more

Help your peers!
Select
Add answer anonymously...

Amdocs Software Engineer interview questions & answers

A Software Engineer was asked 4d agoQ. What do you know about relational databases?
A Software Engineer was asked 4mo agoQ. Write a JUnit test case.
A Software Engineer was asked 6mo agoQ. What is the difference between arrays and ArrayLists in Java?

Popular interview questions of Software Engineer

A Software Engineer was asked 5d agoQ1. What do you know about relational databases?
A Software Engineer was asked 4mo agoQ2. Write a JUnit test case.
A Software Engineer was asked 6mo agoQ3. What is the difference between arrays and ArrayLists in Java?
Amdocs Software Engineer 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