Search⌘ K
AI Features

Solution: Contains Duplicate II

Explore the sliding window approach to check if an array contains duplicates within a given range k. Understand how to maintain a set to track elements and efficiently identify duplicates, improving your coding interview problem-solving skills.

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 ...