Question bank › Greedy
Dsa Greedy Easy

Maximum Coins from Stacks

You have several stacks of coins and you want to maximize the number of coins you collect. You can only take coins from the top of any stack, and you want to ensure that you take coins in such a way that you maximize the sum of the coins taken. Input: The first line contains an integer n (1 ≤ n ≤ 100) - the number of stacks. The next line contains n integers, each representing the number of coins in that stack. You may take from each stack a number of coins equal to or less than the number of coins in the stack. Output: Print the maximum number of coins you can collect by taking from the stacks optimally. Example: Input: 5 3 7 4 1 2 Output: 17

Key concepts

greedysorting

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.