Solved "Lemonade Change" problem using Greedy Algorithm

🌟 Day 78 of #100DaysOfCode Today I solved the “Lemonade Change” 🍋 problem — a great exercise in Greedy Algorithms and logical decision-making. 🧩 The Problem: You’re running a lemonade stand where each glass costs $5. Customers pay with $5, $10, or $20 bills — and you must give the correct change for every transaction in order. 💡 The Approach: Maintain counts of $5 and $10 bills. For each customer: If they pay with $5 → keep it. If they pay with $10 → give one $5 as change. If they pay with $20 → try to give one $10 + one $5 (prefer larger denominations first), else give three $5 bills. If at any point change can’t be given → return false. ⚙️ Concept Used: ➡️ Greedy Algorithm — always make the optimal local decision (use larger bills first) to ensure global success. ✅ Takeaway: A simple problem that strengthens understanding of conditional logic, greedy thinking, and resource tracking in real-world scenarios. 💻✨ #DSA #Coding #CPlusPlus #ProblemSolving #GreedyAlgorithm #Programming #CodeNewbie #100DaysOfCodeChallenge

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories