n: each step moves the last element to the front. For instance, [1, 3, 6, 8, 8] becomes [6, 8, 8, 1, 3] after three steps and returns to its original form after n steps. The array may contain repeated values.
Given the resulting array values, return its smallest element using as few steps as you can.
Think about it: how do repeats change the complexity compared with all-distinct elements?values=[6, 8, 8, 1, 3] → 1
The sorted array [1, 3, 6, 8, 8] was shifted by 3 positions; the minimum is 1.
values=[4, 4, 4, 4, 2, 4] → 2
Because of the repeats, the ends and the middle all hold 4, which alone does not tell which half the minimum is in. The answer is 2.
values=[-3, 0, 7] → -3
A shift by the full length brought the array back to its sorted form.
values is a sorted array rotated by 1 to n positionsvalues=[6, 8, 8, 1, 3]
1
Run checks the first 3 tests in your browser. Submit checks all 121 tests on the server, hidden ones included.