Day 16 of DSA Journey: Binary Search Variations

🚀 Day 16 of my DSA Journey (LeetCode + Java) Today was all about Binary Search and its powerful variations. All three problems looked simple at first, but required careful observation and multiple dry runs before finalizing the logic. ✅ Problems Solved Today: LC 69 – Sqrt(x) LC 162 – Find Peak Element LC 153 – Find Minimum in Rotated Sorted Array 🧠 My Experience Solving These: 🔸 69. Sqrt(x) At first, I thought this was going to be very easy… But it turned out tricky. I used a while loop with binary search, checked mid * mid, and after multiple dry runs finally got the correct logic. Handled overflow using (long)mid * mid. 🔸 162. Find Peak Element This one was fairly easy. Used binary search + mid comparison with mid + 1. If right side is increasing → move right Else → search left. Finally returned the left pointer. 🔸 153. Find Minimum in Rotated Sorted Array Very similar to the previous one. Binary search + comparing arr[mid] with arr[right]. Left or right movement automatically narrowed down the minimum element. Clean and elegant solution. 📌 Key Takeaway Today: Binary Search is much more than searching a number. It’s about understanding patterns: ✔ Compare mid with mid+1 or right ✔ Use sorted halves intelligently ✔ Shrink the search space correctly ✔ Trust the pointers—left and right always move toward the answer Mastering these patterns makes many “hard-looking” problems simple. 💪 Step-by-step consistency. Every day I’m building stronger logic. On to Day 17! 🚀 #DSA #LeetCode #Java #BinarySearch #ProblemSolving #CodingJourney #Consistency #LearningDaily

To view or add a comment, sign in

Explore content categories