values of length n. You may rotate it left by k positions (0 ≤ k < n), turning it into [values[k], ..., values[n − 1], values[0], ..., values[k − 1]].
After the rotation, every element whose value is at most its new index earns one point. For example, [3, 0, 2, 1] earns 3 points: for 0 at index 1, 2 at index 2 and 1 at index 3.
Return the shift k that earns the most points. If several shifts tie, return the smallest one.values=[2, 0, 1] → 1
Shift 0: [2, 0, 1] scores for 0 and 1, total 2. Shift 1: [0, 1, 2] scores for all three, total 3. Shift 2: [1, 2, 0] scores only for 0, total 1. Shift 1 wins.
values=[0, 0] → 0
Both zeros score under any shift, so we take the smallest one, 0.
values=[1, 2, 3, 0] → 3
n = len(values) ≤ 10⁵values[i] < nvalues=[2, 0, 1]
1
Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.