```
class Solution:
# @param {integer[]} nums
# @param {integer} k
# @param {integer} t
# @return {boolean}
def containsNearbyAlmostDuplicate(self, nums, k, t):
ind = sorted(range(len(nums)), key = lambda x: nums[x])
for i in range(len(nums)-1):
j = i + 1
while j < len(nums) and nums[ind[j]] - nums[ind[i]] <= t:
if abs(ind[i]-ind[j]) <= k:
return True
j += 1
return False
```

ind is an array of the indexes of sorted num. Iterate through ind to check if nums are within t and ind are within k.