FAANG Interview - Leetcode 220 Contains Duplicate III

I want to share something about leetcode Question 220) Contains Duplicate III. https://leetcode.com/problems/contains-duplicate-iii/

Note that this will not give Time Limit Exceeded and leetcode Accepts this!

class Solution:
    def containsNearbyAlmostDuplicate(self, nums, k: int, t: int) -> bool:
        def isValidDuplicates():
            d = {}
            for i in range(len(nums)):
                if nums[i] in d and abs(d[nums[i]] - i) <= k:
                    return True
                d[nums[i]] = i
            return False

        if t == 0:
            return isValidDuplicates()

        for i in range(len(nums)):
            for j in range(i + 1, min(len(nums), i + k + 1)):
                if abs(nums[i] - nums[j]) <= t:
                    return True
        return False

        for i in range(0, len(nums)):
            for j in range(1, len(nums)):
                if i == j:
                    continue
                elif abs(nums[j]-nums[i]) <= t and abs(j-i) <= k:
                    return True

        return False

But how come this will give Time Limit exceeded?

class Solution:
    def containsNearbyAlmostDuplicate(self, nums, k: int, t: int) -> bool:
		if t == 0 and len(nums) == len(set(nums)):
					return False

			for i in range(0, len(nums)):
				for j in range(1, len(nums)):
					if i == j:
						continue
					elif abs(nums[j]-nums[i]) <= t and abs(j-i) <= k:
						return True

			return False

Someone please help me!!!!

Comments (1)