1
class Solution:
2
def bestRotation(self, nums: List[int]) -> int:
3
diff = [i - nums[i] for i in range(len(nums))]
4

5
target = 0
6
qualified = []
7
for d in diff:
8
if d >= target:
9
heappush(qualified, d)
10
smallest_rotate = 0
11
highest_score = len(qualified)
12

13
for rotate in range(1, len(nums)):
14
target += 1
15
while qualified and qualified[0] < target:
16
heappop(qualified)
17
modified = diff[rotate - 1] + len(diff)
18
heappush(qualified, modified)
19
score = len(qualified)
20
if score > highest_score:
21
smallest_rotate = rotate
22
highest_score = score
23

24
return smallest_rotate

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0