Logic Over Lines

Today I started the DSA with C++ 1.0 Cohort led by Hitesh Choudhary Sir and Prateek Sir, and the very first class left me with a golden insight — DSA is not just about solving problems, but solving them optimally. 💡
Here’s the simple yet powerful problem we explored:
You have 9 balls: 8 of equal weight and 1 heavier. Using a weighing scale, find the heavier ball in the minimum number of comparisons.
🔁 Naive Approach: Compare each ball one by one using a loop.
❌ Worst-case: 8 comparisons
⚡ Optimized Approach (Divide & Conquer): Split into 3 sets of 3 balls.
Compare Set A vs Set B
If equal → heavy ball in Set C
If not → heavy set has it Repeat the process with 3 balls.
✅ Only 2 comparisons!
🎯 Takeaway: "More lines of code ≠ higher complexity." Sometimes, a few extra lines with the right logic can drastically reduce time complexity. It's all about thinking like a problem solver, not just a coder.
🔥 This cohort is off to a fantastic start, and I’m excited to keep sharing insights as we go deeper into the world of DSA. Let’s crack it together! 💻
#chaiCode #DSAwithC++ #HiteshChoudhary #PratikSir #LearningInPublic #DSA #ProblemSolving #PeerlistBlog #CodeNewbie #chaicode
Subscribe to my newsletter
Read articles from Aryan Jaiswal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
