Contains Duplicate II

Easy

Company Tags

You are given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k, otherwise return false.

Example 1:

Input: nums = [1,2,3,1], k = 3

Output: true

Example 2:

Input: nums = [2,1,2], k = 1

Output: false

Constraints:

  • 1 <= nums.length <= 100,000
  • -1,000,000,000 <= nums[i] <= 1,000,000,000
  • 0 <= k <= 100,000


Company Tags

Please upgrade to NeetCode Pro to view company tags.

nums =

k =