Reported May 2020
Bloombergbinary search

Minimum in a Rotated Sorted Array

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

The edge case that breaks a naive solution here is the array that was never rotated. Bloomberg reported this one in May 2020, and it's a clean binary search on a rotated sorted array. If you've got an OA coming, expect to find the minimum in logarithmic time, not with a linear scan. Values are distinct, which makes the logic simpler than the duplicate version. Most people know the idea and still lose points on the loop bounds. If you blank mid-assessment, StealthCoder is the invisible safety net on your screen that reads the problem and hands you the answer. Know the trick first, though.

The problem

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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: compare the middle element to the rightmost element, not the left. If values[mid] > values[right], the minimum sits strictly right of mid, so set lo = mid + 1. Otherwise the minimum is at mid or to its left, so set hi = mid. Loop while lo < hi and return values[lo]. That handles the unrotated case for free, because values[mid] is never greater than values[right] in a sorted array, so hi keeps shrinking toward index 0. The common pitfall is comparing against values[left] and then fumbling the unrotated input like [11,13,15,17]. Another is using hi = mid - 1 and skipping the answer. A linear min() scan returns the right value but fails the logarithmic requirement. If you freeze on the bounds during the live OA, StealthCoder can supply the loop while you keep your composure.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Minimum in a Rotated Sorted Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as find minimum in rotated sorted array. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum in a Rotated Sorted Array FAQ

What's the trick to Minimum in a Rotated Sorted Array?+

Binary search comparing values[mid] to values[right]. If mid is greater, the minimum is to the right, so lo = mid + 1. Otherwise hi = mid. Stop when lo equals hi. Comparing to the right end handles rotated and unrotated arrays with the same code.

How hard is this problem really?+

Medium on paper, easy if you've seen it. The idea is short, but off-by-one errors in the loop bounds trip people up. Write lo < hi, use hi = mid, and test it on a two-element array and an unrotated one before submitting.

Can I just use min(values) for the Bloomberg OA?+

It returns the correct value, but the problem explicitly asks for logarithmic time. With up to 10^5 elements, a linear scan may pass small tests but it ignores the stated requirement. Write the binary search so you match what the question wants.

What edge cases should I test?+

Test the unrotated array like [11,13,15,17], a single-element array, a two-element rotated array like [2,1], and a pivot near the end like [2,3,4,5,1]. Values are distinct, so you don't need duplicate handling. These cases catch most bound mistakes.

How do I prepare for this in 48 hours?+

Write the binary search from memory three times, once on a rotated input, once unrotated, and once with two elements. Trace lo, hi, and mid by hand. That's enough. The pattern is small, so you're drilling the invariant, not memorizing code.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it