Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
minimum-seconds-to-equalize-a-circular-array.json35 linesDownload Raw Back to root
1{2  "id": 2920,3  "name": "minimum-seconds-to-equalize-a-circular-array",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/minimum-seconds-to-equalize-a-circular-array/",6  "date": "2023-07-22",7  "task_description": "You are given a **0-indexed** array `nums` containing `n` integers. At each second, you perform the following operation on the array: For every index `i` in the range `[0, n - 1]`, replace `nums[i]` with either `nums[i]`, `nums[(i - 1 + n) % n]`, or `nums[(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_. **Example 1:** ``` **Input:** nums = [1,2,1,2] **Output:** 1 **Explanation:** We can equalize the array in 1 second in the following way: - At 1st second, replace values at each index with [nums[3],nums[1],nums[3],nums[3]]. After replacement, nums = [2,2,2,2]. It can be proven that 1 second is the minimum amount of seconds needed for equalizing the array. ``` **Example 2:** ``` **Input:** nums = [2,1,3,3,2] **Output:** 2 **Explanation:** We can equalize the array in 2 seconds in the following way: - At 1st second, replace values at each index with [nums[0],nums[2],nums[2],nums[2],nums[3]]. After replacement, nums = [2,3,3,3,3]. - At 2nd second, replace values at each index with [nums[1],nums[1],nums[2],nums[3],nums[4]]. After replacement, nums = [3,3,3,3,3]. It can be proven that 2 seconds is the minimum amount of seconds needed for equalizing the array. ``` **Example 3:** ``` **Input:** nums = [5,5,5,5] **Output:** 0 **Explanation:** We don't need to perform any operations as all elements in the initial array are the same. ``` **Constraints:** `1 <= n == nums.length <= 105` `1 <= nums[i] <= 109`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [1,2,1,2]",12      "output": "1 "13    },14    {15      "label": "Example 2",16      "input": "nums = [2,1,3,3,2]",17      "output": "2 "18    },19    {20      "label": "Example 3",21      "input": "nums = [5,5,5,5]",22      "output": "0 "23    }24  ],25  "constraints": [26    "For every index i in the range [0, n - 1], replace nums[i] with either nums[i], nums[(i - 1 + n) % n], or nums[(i + 1) % n].",27    "1 <= n == nums.length <= 105",28    "1 <= nums[i] <= 109"29  ],30  "python_template": "class Solution(object):\n    def minimumSeconds(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        ",31  "java_template": "class Solution {\n    public int minimumSeconds(List<Integer> nums) {\n        \n    }\n}",32  "metadata": {33    "func_name": "minimumSeconds"34  }35}