Search
⌘K

Leetcode 2817. Minimum Absolute Difference Between Elements With Constraint

Given an array nums and integer x, find the minimum |nums[i] - nums[j]| over all index pairs with |i - j| >= x. The core challenge is maintaining a searchable set of values at least x apart (e.g., a sliding window with an ordered set) to efficiently query the closest neighbor for each element in O(n log n) time for n up to 1e5.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.