Algorithms
Medium
2817
3000
Minimum Absolute Difference Between Elements With Constraint
minimum-absolute-difference-between-elements-with-constraint
"""
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
"""
class Solution:
    def minAbsoluteDifference(self, nums: List[int], x: int) -> int:
        
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


Please complete the code below to solve above prblem:
```python
class Solution:
    def minAbsoluteDifference(self, nums: List[int], x: int) -> int:
        
```

my_solution = Solution()

test_input = { "nums": [4,3,2,4], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [5,3,2,10,15], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [1,2,3,4], "x": 3 }
assert my_solution.minAbsoluteDifference(**test_input) == 3

test_input = { "nums": [1,67], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 66

test_input = { "nums": [7,398], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 391

test_input = { "nums": [12,141], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 129

test_input = { "nums": [21,75], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 54

test_input = { "nums": [22,147], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 125

test_input = { "nums": [25,197], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 172

test_input = { "nums": [27,275], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 248

test_input = { "nums": [37,192], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 155

test_input = { "nums": [41,163], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 122

test_input = { "nums": [45,49], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [48,195], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 147

test_input = { "nums": [68,68], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [71,4], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 67

test_input = { "nums": [72,169], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 97

test_input = { "nums": [74,62], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 12

test_input = { "nums": [75,1], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 74

test_input = { "nums": [76,49], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 27

test_input = { "nums": [88,72], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 16

test_input = { "nums": [99,370], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 271

test_input = { "nums": [103,39], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 64

test_input = { "nums": [109,99], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 10

test_input = { "nums": [111,161], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 50

test_input = { "nums": [113,117], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [119,184], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 65

test_input = { "nums": [122,118], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [123,13], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 110

test_input = { "nums": [123,162], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 39

test_input = { "nums": [126,69], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 57

test_input = { "nums": [127,18], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 109

test_input = { "nums": [127,346], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 219

test_input = { "nums": [132,110], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [134,23], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 111

test_input = { "nums": [136,150], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 14

test_input = { "nums": [139,215], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 76

test_input = { "nums": [153,3], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 150

test_input = { "nums": [156,67], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 89

test_input = { "nums": [160,168], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 8

test_input = { "nums": [161,93], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 68

test_input = { "nums": [164,81], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 83

test_input = { "nums": [167,83], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 84

test_input = { "nums": [174,58], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 116

test_input = { "nums": [174,102], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 72

test_input = { "nums": [175,137], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 38

test_input = { "nums": [176,99], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 77

test_input = { "nums": [178,179], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [228,359], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 131

test_input = { "nums": [243,280], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 37

test_input = { "nums": [283,62], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 221

test_input = { "nums": [288,149], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 139

test_input = { "nums": [293,278], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 15

test_input = { "nums": [327,425], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 98

test_input = { "nums": [337,187], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 150

test_input = { "nums": [346,160], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 186

test_input = { "nums": [347,369], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [355,199], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 156

test_input = { "nums": [413,311], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 102

test_input = { "nums": [417,320], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 97

test_input = { "nums": [418,131], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 287

test_input = { "nums": [3274,71], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3203

test_input = { "nums": [5,14,81], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 76

test_input = { "nums": [9,25,15], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 6

test_input = { "nums": [9,113,136], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 23

test_input = { "nums": [13,19,12], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [13,94,59], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 46

test_input = { "nums": [14,111,16], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 2

test_input = { "nums": [17,173,69], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 52

test_input = { "nums": [24,39,28], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [32,129,93], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 36

test_input = { "nums": [33,18,131], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 15

test_input = { "nums": [36,19,27], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 9

test_input = { "nums": [40,18,17], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [43,49,20], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 23

test_input = { "nums": [44,186,163], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 119

test_input = { "nums": [56,23,158], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 33

test_input = { "nums": [62,37,182], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 120

test_input = { "nums": [63,116,12], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 51

test_input = { "nums": [66,345,278], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 212

test_input = { "nums": [67,81,165], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 98

test_input = { "nums": [70,184,70], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [73,106,172], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 33

test_input = { "nums": [74,199,57], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 17

test_input = { "nums": [83,14,14], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [86,1,129], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 43

test_input = { "nums": [87,194,107], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 20

test_input = { "nums": [88,75,122], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 34

test_input = { "nums": [93,96,28], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3

test_input = { "nums": [95,86,132], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 37

test_input = { "nums": [96,41,24], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 17

test_input = { "nums": [116,6,3], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3

test_input = { "nums": [120,102,184], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 18

test_input = { "nums": [123,113,20], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 10

test_input = { "nums": [125,14,141], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 16

test_input = { "nums": [126,2,180], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 54

test_input = { "nums": [136,24,114], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [136,177,98], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 38

test_input = { "nums": [136,177,123], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 13

test_input = { "nums": [136,178,18], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 118