Tap here to switch tabs
Problem
Submissions

Problem: Minimum Seconds to Equalize a Circular Array

Try to solve the Minimum Seconds to Equalize a Circular Array problem.

Statement

You are given a 00 indexed circular array nums containing nn integers.

In each second, for every index i from 00 to n−1n - 1 simultaneously, you can replace the value at nums[i] with any of the following values:

  • nums[i]

  • nums[(i - 1 + n) % n]

  • nums[(i + 1) % n]

Return the minimum number of seconds required to make all elements in nums equal.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Seconds to Equalize a Circular Array

Try to solve the Minimum Seconds to Equalize a Circular Array problem.

Statement

You are given a 00 indexed circular array nums containing nn integers.

In each second, for every index i from 00 to n−1n - 1 simultaneously, you can replace the value at nums[i] with any of the following values:

  • nums[i]

  • nums[(i - 1 + n) % n]

  • nums[(i + 1) % n]

Return the minimum number of seconds required to make all elements in nums equal.

Constraints:

  • 1≤n==1 \leq n == nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9