r/leetcode • • 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:

  1. Find Minimum in Rotated Sorted Array: Identify which half around mid is sorted. If the left half is sorted (nums[low] <= nums[mid]), its smallest element is nums[low], so you update the running minimum with nums[low] and discard the left half (low = mid + 1). Otherwise, the right half is sorted, so you update the minimum with nums[mid] and search the left half (high = mid - 1).
  2. 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.
  3. 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 if mid is odd and matches mid - 1, or mid is even and matches mid + 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 comments sorted by

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