Yogesh ..’s Post

Day 41/100 | #100DaysOfDSA 💻🚀 Today’s problem: Find the Duplicate Number Goal: Given an array with n + 1 numbers where each number is in the range [1, n], find the duplicate number without modifying the array and using constant extra space. Approach: Binary Search on Answer Idea: • The duplicate must lie in the range 1 → n • Count how many numbers are ≤ mid • If the count is greater than mid → duplicate is in the left half • Otherwise search the right half Key insight: Using the pigeonhole principle, if more numbers fall in a range than expected, a duplicate must exist there. Time Complexity: O(n log n) Space Complexity: O(1) Big takeaway: Binary search isn’t just for sorted arrays — it can also be applied on the range of possible answers. Day 41 — patterns getting clearer. 🔥 #100DaysOfCode #LeetCode #DSA #Algorithms #BinarySearch #Java #CodingJourney #InterviewPrep #ProblemSolving #TechCommunity

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories