2817. Min Abs Diff Between Elms With Constraint
unknown
typescript
a year ago
433 B
7
Indexable
Never
function minAbsoluteDifference(nums: number[], x: number): number { if(x === 0) { return 0; } const n = nums.length; let res = Number.MAX_SAFE_INTEGER; for(let i = 0; i < n - x; i++) { for(let j = i + x; j < n; j++) { res = Math.min(res, Math.abs(nums[i] - nums[j])); if(res === 0) { return 0; } } } return res; };