Problem · Array

Minimum in a Rotated Sorted Array

Learn this problem
MediumGoldman Sachs logoGoldman SachsFULLTIMEONSITE INTERVIEW

Problem statement

An array values was originally sorted in strictly increasing order and then rotated at an unknown pivot. The array may also be unrotated.

Return its minimum value. Your algorithm should run in logarithmic time.

Function

findMinimum(values: int[]) → int

Examples

Example 1

values = [3,4,5,1,2]return = 1

The sorted order was rotated so that 1, the minimum, begins the final increasing segment.

Example 2

values = [4,5,6,7,0,1,2]return = 0

The rotation pivot places 0 after 7.

Example 3

values = [11,13,15,17]return = 11

The array is unrotated, so its first value is the minimum.

Constraints

  • 1 <= values.length <= 10^5
  • -2^31 <= values[i] <= 2^31 - 1
  • All values are distinct.
  • values is a rotation of a strictly increasing array.

More Goldman Sachs problems

drafts saved locally
public int findMinimum(int[] values) {
    // Write your solution here.
}
values[3,4,5,1,2]
expected1
checking account