How do you implement binary search on a rotated sorted array?

Technical
Hard
Infosys
53.3K views

Binary search on a rotated array requires modifications to handle the pivot point where the order breaks.

Why Interviewers Ask This

This tests deep understanding of binary search logic and conditional branching. Interviewers evaluate if you can adapt standard algorithms to non-standard data structures. It shows your ability to reason about array partitions and pivot points.

How to Answer This Question

Explain the standard binary search first, then introduce the rotation aspect. Describe how to determine which half is sorted by comparing mid with low and high. Adjust the search range based on where the target lies relative to the sorted half. Handle edge cases where duplicates might exist if applicable.

Key Points to Cover

  • Identify sorted half
  • Conditional range adjustment
  • Pivot point handling
  • O(log n) complexity

Sample Answer

Standard binary search fails here because the array is rotated. I first check if the left half is sorted by comparing arr[mid] with arr[low]. If it is, I check if the target lies within this range; if so, I search left,…

Common Mistakes to Avoid

  • Treating it as a standard binary search
  • Incorrectly identifying the sorted side
  • Failing to handle duplicates

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 165 Technical questionsBrowse all 100 Infosys questions