PPractick

DSA interview question

Find the Minimum in a Rotated Sorted Array

Medium · Algorithms · Topics: binary search, rotated array

The problem

A weather station's circular buffer holds hourly temperatures in increasing order since midnight, but it wraps around, so the stored array looks like [3, 4, 5, 1, 2]. The smallest value, which is where the sequence restarted, marks the rotation point. Scanning is O(n); binary search finds it in O(log n) by comparing the middle element with the rightmost one. If the middle is bigger than the right end, the drop (and the minimum) must be to the right of mid; otherwise the minimum is at mid or to its left.

Example: [4, 5, 6, 7, 0, 1, 2] → 0.

Function signature

int findMin(const vector<int>& nums);  // distinct values, rotated increasing array, non-empty

Test cases

Input numsOutputExplanation
[3, 4, 5, 1, 2]1
[4, 5, 6, 7, 0, 1, 2]0
[11, 13, 15, 17]11Not rotated
[2, 1]1
[1]1

(Confirm: values are distinct; the array is a rotation of an increasing array.)

How interviewers phrase it

Clarifying questions to ask

  1. Are the values distinct?
  2. Could the array be unrotated?
  3. Return the value or its index?

Follow-ups to expect

  1. "Why compare with the right end, not the left?"
  2. "Why hi = mid and not hi = mid − 1?"
  3. "What changes with duplicates?"
  4. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in