Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes194downloads
minimum-operations-to-make-array-elements-zero.json46 linesDownload Raw Back to root
1{2  "id": 3744,3  "name": "minimum-operations-to-make-array-elements-zero",4  "difficulty": "Hard",5  "link": "https://leetcode.com/problems/minimum-operations-to-make-array-elements-zero/",6  "date": "2025-03-16",7  "task_description": "You are given a 2D array `queries`, where `queries[i]` is of the form `[l, r]`. Each `queries[i]` defines an array of integers `nums` consisting of elements ranging from `l` to `r`, both **inclusive**. In one operation, you can: Select two integers `a` and `b` from the array. Replace them with `floor(a / 4)` and `floor(b / 4)`. Your task is to determine the **minimum** number of operations required to reduce all elements of the array to zero for each query. Return the sum of the results for all queries. **Example 1:** **Input:** queries = [[1,2],[2,4]] **Output:** 3 **Explanation:** For `queries[0]`: The initial array is `nums = [1, 2]`. In the first operation, select `nums[0]` and `nums[1]`. The array becomes `[0, 0]`. The minimum number of operations required is 1. For `queries[1]`: The initial array is `nums = [2, 3, 4]`. In the first operation, select `nums[0]` and `nums[2]`. The array becomes `[0, 3, 1]`. In the second operation, select `nums[1]` and `nums[2]`. The array becomes `[0, 0, 0]`. The minimum number of operations required is 2. The output is `1 + 2 = 3`. **Example 2:** **Input:** queries = [[2,6]] **Output:** 4 **Explanation:** For `queries[0]`: The initial array is `nums = [2, 3, 4, 5, 6]`. In the first operation, select `nums[0]` and `nums[3]`. The array becomes `[0, 3, 4, 1, 6]`. In the second operation, select `nums[2]` and `nums[4]`. The array becomes `[0, 3, 1, 1, 1]`. In the third operation, select `nums[1]` and `nums[2]`. The array becomes `[0, 0, 0, 1, 1]`. In the fourth operation, select `nums[3]` and `nums[4]`. The array becomes `[0, 0, 0, 0, 0]`. The minimum number of operations required is 4. The output is 4. **Constraints:** `1 <= queries.length <= 105` `queries[i].length == 2` `queries[i] == [l, r]` `1 <= l < r <= 109`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "queries = [[1,2],[2,4]]",12      "output": "3 "13    },14    {15      "label": "Example 2",16      "input": "queries = [[2,6]]",17      "output": "4 "18    }19  ],20  "constraints": [21    "Select two integers a and b from the array.",22    "Replace them with floor(a / 4) and floor(b / 4).",23    "The initial array is nums = [1, 2].",24    "In the first operation, select nums[0] and nums[1]. The array becomes [0, 0].",25    "The minimum number of operations required is 1.",26    "The initial array is nums = [2, 3, 4].",27    "In the first operation, select nums[0] and nums[2]. The array becomes [0, 3, 1].",28    "In the second operation, select nums[1] and nums[2]. The array becomes [0, 0, 0].",29    "The minimum number of operations required is 2.",30    "The initial array is nums = [2, 3, 4, 5, 6].",31    "In the first operation, select nums[0] and nums[3]. The array becomes [0, 3, 4, 1, 6].",32    "In the second operation, select nums[2] and nums[4]. The array becomes [0, 3, 1, 1, 1].",33    "In the third operation, select nums[1] and nums[2]. The array becomes [0, 0, 0, 1, 1].",34    "In the fourth operation, select nums[3] and nums[4]. The array becomes [0, 0, 0, 0, 0].",35    "The minimum number of operations required is 4.",36    "1 <= queries.length <= 105",37    "queries[i].length == 2",38    "queries[i] == [l, r]",39    "1 <= l < r <= 109"40  ],41  "python_template": "class Solution(object):\n    def minOperations(self, queries):\n        \"\"\"\n        :type queries: List[List[int]]\n        :rtype: int\n        \"\"\"\n        ",42  "java_template": "class Solution {\n    public long minOperations(int[][] queries) {\n        \n    }\n}",43  "metadata": {44    "func_name": "minOperations"45  }46}