Day 19 of Problem Solving Series In Python

Day 19 of Problem Solving Series In Python | Geethu Talks

Day 19 of Problem Solving Series

Day 19 of Problem Solving Series

👋 Hi friends! Geethu Talks ki welcome. Mundu nunchi, venaka nunchi okkate ela chaduvuthaam? Ee roju palindrome check cheddam, two pointers technique tho.

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

🧩 Real-life Problem

Oka booking reference code 12321 mundu nunchi, venaka nunchi okkate undha ani check cheyyali.

📋 Task: Code teesukuni palindrome ena check cheyyandi.
📥 Sample input: 12321
📤 Sample output: Palindrome code!

📚 Concepts Covered

  • ↔️ Two pointers (left & right)
  • 🔁 while left < right
  • 🚩 Flag variable
  • 🛑 break

🧠 Step 1: Logic Build Cheddam

Rendu chepala nunchi lopaliki vasthaam:

  1. Left = 0, Right = last index
  2. Left and right characters same na check
  3. Veru ayithe: palindrome kaadu, stop
  4. Same ayithe: left → mundu, right → venaka. Meet ayye varaku repeat
1 2 3 2 1  →  1=1 ✔️, 2=2 ✔️, 3 (middle)

💡 Analogy: Rendu friends rendu chepala nunchi nadichi madhyalo kalavadam laga. Prathi adugulo vallu same ga undali.

💻 Step 2: Python Code

code = input("Enter booking code: ")
left = 0
right = len(code) - 1
is_palindrome = True

while left < right:
    if code[left] != code[right]:
        is_palindrome = False
        break
    left = left + 1
    right = right - 1

if is_palindrome:
    print("Palindrome code!")
else:
    print("Not a palindrome")

✅ Output
Enter booking code: 12321
Palindrome code!

🔍 Line by line


CodeMeaning
left = 0Start pointer
right = len(code) - 1Last index (len – 1)
code[left] != code[right]Ye chepa characters veru ayithe
breakMismatch dorikagane aapeyyadam
left + 1, right - 1Pointers lopaliki

⚠️ Common Mistake Alert

❌ Wrong: Capital/small difference ignore cheyyakapothe Madam palindrome kaadu ani vasthundi

code = "Madam"
print(code[0] == code[4])   # 'M' vs 'm'

Result:
False

✅ Right: Mundu code = code.lower() chesi tarvatha check cheyyandi.

💡 Bonus tip: Loop lo pointers move cheyyakapothe loop eppatiki aagadu (infinite loop). Last index eppudu len() - 1.

📝 Quick Recap

  • ✔️ Two pointers: rendu chepala nunchi
  • ✔️ Mismatch dorikithe break
  • ✔️ Case problem kosam lower()

🏋️ Practice Problems

🟢 Easy: ‘python’ ni reverse chesi print cheyyandi (loop tho).
Expected output: nohtyp


🟡 Medium: Spaces and case ignore chesi ‘Nurses Run’ palindrome ena check cheyyandi.
Expected output: Palindrome


🔴 Challenge: [‘madam’, ‘python’, ‘level’, ‘code’, ‘noon’] lo palindromes entha?
Expected output: 3


💬 Mee answers comments lo share cheyyandi!

🚀 Next: Day 20 – Missing Jersey Number

Follow @GeethuTalks and stay tuned! 💛

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

check out our website for more resources

Day 19 of Problem Solving Series Day 19 of Problem Solving Series Day 19 of Problem Solving Series

Leave a Comment