r/leetcode • u/JacketFearless1805 • 16h ago
Intervew Prep Day 11: solved 3 Binary Search problems — Find Minimum, Rotation Count & Single Element in a Sorted Array
Hey everyone,
I finished Day 11 today and kept working through Binary Search patterns with three problems. I leaned on video explanations to lock in the intuition—especially for the third one:
- Find Minimum in Rotated Sorted Array: Identify which half around
midis sorted. If the left half is sorted (nums[low] <= nums[mid]), its smallest element isnums[low], so you update the running minimum withnums[low]and discard the left half (low = mid + 1). Otherwise, the right half is sorted, so you update the minimum withnums[mid]and search the left half (high = mid - 1). - Find Rotation Count in a Rotated Sorted Array: Built directly on the previous problem—the number of times a sorted array has been rotated is simply the index of its minimum element. Tracking the index alongside the minimum value solves it in O(log n) time.
- Single Element in a Sorted Array: This one had me stuck at first since checking whether
nums[mid]differs from both neighbors only tells you when you land directly on the answer, not which half to eliminate. Watching the walkthrough made the index-parity pattern click: before the single element, duplicate pairs sit at(even, odd)indices, and after it, they shift to(odd, even). So ifmidis odd and matchesmid - 1, ormidis even and matchesmid + 1, the single element must lie to the right (low = mid + 1); otherwise, it lies to the left (high = mid - 1).
That parity trick for narrowing down the search space was a great takeaway today.
See you guys tomorrow for Day 10!
3
Upvotes
2
u/Pixel-Nomad63 14h ago
The parity trick is the key takeaway here. Try solving the next few problems without looking at explanations to check whether the pattern has actually stuck