2808. Minimum Seconds to Equalize a Circular Array
You are given a 0-indexed array
nums
containingn
integers.At each second, you perform the following operation on the array:
- For every index
i
in the range[0, n - 1]
, replacenums[i]
with eithernums[i]
,nums[(i - 1 + n) % n]
, ornums[(i + 1) % n]
.Note that all the elements get replaced simultaneously.
Return the minimum number of seconds needed to make all elements in the array
nums
equal.
1 | class Solution { |