Skip to content
Preptima
mediumCodingMidSenior

Find the rotation point of a rotated sorted array, then do it again when the array has duplicates.

Binary search for the rotation point by comparing the middle element with the right end. If it is larger, the break lies to the right; otherwise it is at mid or before it. That is O(log n). With duplicates an equal comparison says nothing, so you drop the right end, and the worst case becomes O(n).

4 min readUpdated 2026-10-10Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Binary search for the rotation point against the right end. If a[mid] > a[hi], the order breaks somewhere after mid, so set lo = mid + 1; otherwise the smallest element is at mid or before it, so set hi = mid. That is O(log n) for distinct values. With duplicates, a[mid] == a[hi] tells you nothing, so you drop hi by one, which makes the worst case O(n).

Was this answer helpful?

Likely follow-ups

  • The array was rotated right by an unknown k. Recover k from the rotation point, and say what k means if the array has duplicates.
  • How would you find the maximum instead, and does the right-end comparison still work?
  • The array is all equal except one smaller value. Trace your duplicate-safe loop on it and count the steps.
  • Your caller now wants every target lookup to be O(log n) after one preprocessing pass. What do you store?

Related questions

Related Topics