Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes402downloads
minimum-absolute-difference-between-elements-with-constraint.json35 linesDownload Raw Back to root
1{2  "id": 3000,3  "name": "minimum-absolute-difference-between-elements-with-constraint",4  "difficulty": "Medium",5  "link": "https://leetcode.com/problems/minimum-absolute-difference-between-elements-with-constraint/",6  "date": "2023-08-06",7  "task_description": "You are given a **0-indexed** integer array `nums` and an integer `x`. Find the **minimum absolute difference** between two elements in the array that are at least `x` indices apart. In other words, find two indices `i` and `j` such that `abs(i - j) >= x` and `abs(nums[i] - nums[j])` is minimized. Return_ an integer denoting the **minimum** absolute difference between two elements that are at least_ `x` _indices apart_. **Example 1:** ``` **Input:** nums = [4,3,2,4], x = 2 **Output:** 0 **Explanation:** We can select nums[0] = 4 and nums[3] = 4. They are at least 2 indices apart, and their absolute difference is the minimum, 0. It can be shown that 0 is the optimal answer. ``` **Example 2:** ``` **Input:** nums = [5,3,2,10,15], x = 1 **Output:** 1 **Explanation:** We can select nums[1] = 3 and nums[2] = 2. They are at least 1 index apart, and their absolute difference is the minimum, 1. It can be shown that 1 is the optimal answer. ``` **Example 3:** ``` **Input:** nums = [1,2,3,4], x = 3 **Output:** 3 **Explanation:** We can select nums[0] = 1 and nums[3] = 4. They are at least 3 indices apart, and their absolute difference is the minimum, 3. It can be shown that 3 is the optimal answer. ``` **Constraints:** `1 <= nums.length <= 105` `1 <= nums[i] <= 109` `0 <= x < nums.length`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "nums = [4,3,2,4], x = 2",12      "output": "0 "13    },14    {15      "label": "Example 2",16      "input": "nums = [5,3,2,10,15], x = 1",17      "output": "1 "18    },19    {20      "label": "Example 3",21      "input": "nums = [1,2,3,4], x = 3",22      "output": "3 "23    }24  ],25  "constraints": [26    "1 <= nums.length <= 105",27    "1 <= nums[i] <= 109",28    "0 <= x < nums.length"29  ],30  "python_template": "class Solution(object):\n    def minAbsoluteDifference(self, nums, x):\n        \"\"\"\n        :type nums: List[int]\n        :type x: int\n        :rtype: int\n        \"\"\"\n        ",31  "java_template": "class Solution {\n    public int minAbsoluteDifference(List<Integer> nums, int x) {\n        \n    }\n}",32  "metadata": {33    "func_name": "minAbsoluteDifference"34  }35}