Search⌘ K
AI Features

Solution: Contains Duplicate II

Explore how to apply the sliding window technique to check for duplicate elements within a given index range in an array. This lesson teaches you to maintain a set to track elements within a moving window of size k, enabling you to identify duplicates efficiently with linear time complexity and controlled space usage.

Statement

You are given an integer array, nums, and an integer k. Determine whether two distinct indices, i and j, are in the array, such that nums[i] == nums[j] and the absolute difference between i and j is at most k. Return TRUE if such indices exist; otherwise, return FALSE.

Constraints:

  • 11 \leq nums.length 103\leq 10^3 ...