Trains the technique from
LeetCode 396Rotate FunctionThis 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 calibration dial has n slots arranged in a circle, and slot i holds the signed reading nums[i]. A read head lines up with one slot and then walks all the way round, giving heavier credit to later stops.
Starting the head at slot k, the sequence it visits is B with B[i] = nums[(i + k) % n] for i from 0 to n - 1, and the score of that start is
score(k) = 0 * B[0] + 1 * B[1] + 2 * B[2] + ... + (n - 1) * B[n - 1]
Return the largest score(k) over the n possible starting slots 0 <= k < n. Readings may be negative, so the best start is not always slot 0.
Example 1
Starting at slot 1 the head reads [-1, 6, 2, 4] and scores 0*(-1) + 1*6 + 2*2 + 3*4 = 22, which is the reported value.
Example 2
A one-slot dial has a single start and the only weight is 0, so the score is 0.
Example 3
Every start scores below zero. Starting at slot 1 the head reads [-8, -2, -3] for 0*(-8) + 1*(-2) + 2*(-3) = -8, the value returned.
Example 4
Starting at slot 2 the head reads [-5, 9, 1, 0, 5] and scores 0*(-5) + 1*9 + 2*1 + 3*0 + 4*5 = 31, the value returned.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def best_dial_score(readings: list[int]) -> int:public int bestDialScore(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.