Question bank › Greedy
Dsa Greedy Easy

Optimal Magazine Distribution

You manage a bookstore and have a limited number of magazines to distribute among four sections: fiction, non-fiction, children's books, and magazines. Each section has a maximum number of magazines it can hold. You have a total of 'n' magazines that need to be distributed among these sections where each section should receive its maximum accordingly. Your goal is to maximize the number of magazines distributed. Input format: - The first line contains an integer n (1 ≤ n ≤ 100) - the number of magazines available. - The second line contains four integers, section_caps (c1, c2, c3, c4) (0 ≤ c_i ≤ 100) representing the maximum capacity of each section respectively. Output format: - A single integer representing the maximum number of magazines distributed. Example: Input: 7 2 3 1 5 Output: 6

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.