Day 11 of Problem Solving Series In Python

Day 11 of Problem Solving Series In Python | Geethu Talks

Day 11 of Problem Solving Series In Python

Day 11 of Problem Solving Series

👋 Hi friends! Geethu Talks ki welcome. Canteen lo cheapest snack evaro, min() vadakunda Python lo ela find chestham? ee roju logic nerchukundam.

🎬 Reel chudaledha? Instagram / YouTube lo @GeethuTalks ni follow avvandi.

🧩 Real-life Problem

Canteen lo snacks prices: ₹40, ₹25, ₹60, ₹15, ₹30. Cheapest snack price entha?

📋 Task: Prices list lo nunchi lowest price ni min() vadakunda kanukkondi.
📥 Sample input: [40, 25, 60, 15, 30]
📤 Sample output: Cheapest snack: ₹15

📚 Concepts Covered

  • 📋 List indexing (prices[0])
  • 🔁 List traversal
  • ⚖️ Comparison <
  • 🏆 Running minimum pattern

🧠 Step 1: Logic Build Cheddam

Idi running minimum pattern. Oka champion ni pettukoni, prathi item tho compare chestham:

  1. Mundu first price ni ‘cheapest’ anukundam
  2. Prathi price ni cheapest tho compare cheyyali
  3. Chinna price vasthe cheapest marchali
  4. Loop aipoyaka cheapest answer
40 → 25 → 25 → 15 → 15    Cheapest = ₹15

💡 Analogy: Race lo current leader laga: kotha runner leader kanna fast unte leader marutaru. Last varaku ide jarugutundi.

💻 Step 2: Python Code

prices = [40, 25, 60, 15, 30]
cheapest = prices[0]

for price in prices:
    if price < cheapest:
        cheapest = price

print(f"Cheapest snack: ₹{cheapest}")

✅ Output
Cheapest snack: ₹15

🔍 Line by line


CodeMeaning
cheapest = prices[0]First price tho start
for price in pricesPrathi price ni check
if price < cheapestIppati cheapest kanna takkuva na?
cheapest = priceAite champion marchu
print(...)Final cheapest

⚠️ Common Mistake Alert

❌ Wrong: cheapest = 0 tho start cheyyadam. Zero kanna takkuva price ledu, anduke update avvadu

prices = [40, 25, 60, 15, 30]
cheapest = 0
for price in prices:
    if price < cheapest:
        cheapest = price
print(cheapest)

Result:
0

✅ Right: List lo first item tho start cheyyandi (prices[0]), leda chala pedda number tho.

💡 Bonus tip: Highest kosam same logic: > vadandi. Start value list nundi teesukunte eppudu safe.

📝 Quick Recap

  • ✔️ Running minimum: champion ni update chestu povadam
  • ✔️ Start value list lo nunchi teesukovali
  • ✔️ Same logic tho max kuda find cheyochu

🏋️ Practice Problems

🟢 Easy: Marks [45, 78, 62, 90, 55] lo highest marks entha?
Expected output: 90


🟡 Medium: Snack prices lo cheapest snack position (index) entha?
Expected output: 3


🔴 Challenge: Snack prices lo second cheapest price entha? (hint: first minimum ni remove() chesi malli find cheyyandi)
Expected output: 25


💬 Mee answers comments lo share cheyyandi!

🚀 Next: Day 12 – Counting Likes Above 100

Follow @GeethuTalks and stay tuned! 💛

⬅️ Previous: Day 10 of Problem Solving Series In Python

check out our website for more resources

1 thought on “Day 11 of Problem Solving Series In Python”

Leave a Comment