2817. Min Abs Diff Between Elms With Constraint
unknown
typescript
2 years ago
433 B
17
Indexable
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;
};Editor is loading...