Contains Duplicate II Problem
Contains Duplicate II Problem — ExecCode Easy DSA Practice
Solve the Contains Duplicate II problem on ExecCode. Free online easy DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given an integer array nums and an integer k, return true if there are two distinct indicesiandjin the array such thatnums[i] == nums[j]andabs(i - j) <= k.
Examples
Input {"nums": [1, 2, 3, 1], "k": 3}; Output True. Input {"nums": [1, 0, 1, 1], "k": 1}; Output True. Input {"nums": [1, 2, 3, 1], "k": 2}; Output False
Constraints
1 <= nums.length <= 10^5 -10^9 <= nums[i] <= 10^9 0 <= k <= 10^5
Practice Contains Duplicate II free on ExecCode. Browse DSA problems, topic map, and placement guides.