getBucketID
that takes a number and the width of the buckets (valueDiff + 1) and returns the ID of the bucket this number belongs to.buckets
to store the numbers categorized by their bucket IDs.nums
array, and for each number:
a. Calculate its bucket ID.
b. Check if this bucket or adjacent buckets contain a number that satisfies the abs(nums[i] - nums[j]) <= valueDiff
condition.
c. If such a number is found, return true
.
d. Add the current number to its corresponding bucket in buckets
.
e. If the size of the sliding window exceeds indexDiff
, remove the oldest number from buckets
.false
.