def containsNearbyAlmostDuplicate(self, nums, t, k):

```
d = dict()
for i in range(len(nums)):
if d.get(abs(nums[i] - p) for p in range(t)) is not None:
if i - d[nums[i] - p] <= k:
return True
if d.get(abs(nums[i] + z) for z in range(t)) is not None:
if i - d[nums[i] + z] <= k:
return True
d[nums[i]] = i
return False
```