Dsa
Greedy
Warm-up
Triple Discount
A store has a special promotion: 'For every three items you buy, the cheapest one in that group of three is free.' You can choose how to group the items into sets of three to maximize your discount. Any items left over (not part of a group of three) must be paid for at full price.
Input Format:
A single line of space-separated integers representing the prices of the items you want to buy.
Output Format:
Print the maximum total discount you can receive.
Example:
Input:
10 20 30 40 50 60
Output:
50
(Explanation: Group 1: (60, 50, 40) -> 40 is free. Group 2: (30, 20, 10) -> 10 is free. Total discount = 50.)
Key concepts
sortinggreedy
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