Finding Duplicate Number with Binary Search

🚀 Day 65 of My LeetCode Journey 🚀 🔹 Problem: Find the Duplicate Number (Binary Search Approach) Today, I realized that binary search is not always about searching in a sorted array… Sometimes, we apply binary search on the range of values, not the array itself ✅ 🧠 Key Insight: Choose a mid value. Count how many values in the array are <= mid. If the count is more than mid, the duplicate is in the left half. Otherwise, it's in the right half. We keep narrowing the range until start and end meet — that number is the duplicate. ⚙️ Time Complexity: O(n log n) (no array modification, no extra space) 🧠 Learning: Before jumping to brute-force or extra space solutions, try to reason about the properties of the input. Sometimes the pattern is hidden in the constraints, not in the array. 🔸 Continuous learning. 🔸 Continuous improvement. #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #LearningEveryday #BinarySearch #TechSkills

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories