DSA interview question
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.
int findMin(const vector<int>& nums); // distinct values, rotated increasing array, non-empty
Input nums | Output | Explanation |
|---|---|---|
[3, 4, 5, 1, 2] | 1 | |
[4, 5, 6, 7, 0, 1, 2] | 0 | |
[11, 13, 15, 17] | 11 | Not rotated |
[2, 1] | 1 | |
[1] | 1 |
(Confirm: values are distinct; the array is a rotation of an increasing array.)
hi = mid and not hi = mid − 1?"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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in