All problems
0456HardArrayBinary Search

Lowest Reading On A Turned Drum

Tracked in this browser only
Write code

Trains the technique from

LeetCode 154Find Minimum in Rotated Sorted Array II

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A chart recorder writes its calibration readings around the rim of a drum, one reading per slot, in non-decreasing order all the way round. Repeated readings are ordinary: a stretch of slots may all carry the same figure.

Before the drum was read off, it was turned by somewhere between 1 and n slots, n being the number of slots. The array drum holds the readings as they were then read off, starting from the slot at the index mark and going once round. So drum is the non-decreasing sequence cut at one point, with the tail moved in front of the head.

Return the lowest reading on the drum. Aim to do it without reading every slot: your work should scale with the logarithm of n when the drum holds few repeats.

Examples

Example 1

Input
drum = [78, 78, 12, 45, 45, 61]
Output
12

Read from slot 2 onwards the drum gives 12, 45, 45, 61, 78, 78, which is the non-decreasing round, so the lowest figure on it is 12.

Example 2

Input
drum = [-9, 4, 4, 4, 4]
Output
-9

The readings rise from -9 through four slots reading 4, and -9 is the lowest of them.

Example 3

Input
drum = [206, 206, 206, 206]
Output
206

Every slot carries 206, so that figure is both the highest and the lowest on the drum.

Constraints

  • n == drum.length
  • 1 <= n <= 5000
  • -5000 <= drum[i] <= 5000
  • drum is a non-decreasing sequence turned by between 1 and n slots.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def lowest_reading(drum: list[int]) -> int:
Java
public int lowestReading(int[] drum)
September 7
Apply