Dsa
Two Pointers
Easy
Optimizing Book Distribution
You are given an array of integers representing the number of books on different shelves in a library. Your goal is to redistribute the books such that no shelf has more than a certain limit M books but maximizing the number of shelves used. Compute the maximum number of shelves that can be utilized.\n\nInput Format:
- A single line containing the number of shelves followed by the shelf limits.\n\nOutput Format:
- A single integer representing the maximum number of shelves that can be utilized.\n\nExample:
Input:
5 1 2 3 4 5\nOutput:
4
(Utilize shelves 2, 3, 4, 5 without exceeding the limit)
Key concepts
two_pointersgreedyarray
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