Find Minimum in Rotated Sorted Array II

HardBinary Searchbinary search

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

An array sorted in non-decreasing order was rotated some unknown number of times (possibly zero), so [1,2,2,5] could have become [2,5,1,2]. The array **may contain duplicate values**. Given the rotated array nums, return its smallest element. Try to use fewer comparisons than a full scan. With duplicates the worst case is unavoidably O(n), but typical inputs should run in O(log n).

Examples

Input: nums = [1,3,5]
Output: 1
The array was not rotated, so the first element is the minimum.
Input: nums = [2,2,2,0,1]
Output: 0
The rotation point is between the last 2 and the 0.

Constraints

  • 1 <= nums.length <= 5000
  • -5000 <= nums[i] <= 5000
  • `nums` is a rotation of a non-decreasing array.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More binary search problems