Question bank › Greedy
Dsa Greedy Hard

Warehouse Inventory Management

You are managing a warehouse that stores packages of different sizes. Each package has a specific width and can only be placed in a container if the sum of selected packages' widths does not exceed the container's width limit. Write a program that calculates the maximum number of packages that can fit into a single container while adhering to the width constraint. You will read two numbers, the width limit of the container followed by the widths of the packages available. Output the maximum number of packages that can fit into the container with the given width limit. Input Format: The first line contains an integer W (1 <= W <= 10^6) - the width limit of the container. The second line contains an integer N (1 <= N <= 10^5) - the number of packages. The third line contains N space-separated integers representing the widths of the packages. Output Format: Print a single integer representing the maximum number of packages that can fit in the container. Example: Input: 10 5 2 3 4 5 1 Output: 4

Key concepts

greedysortingarrays

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.