Dsa
Sliding Window
Medium
Contains Duplicate II
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.
Input:
The first line contains space-separated integers representing the array nums (1 ≤ |nums| ≤ 10^5).
The second line contains an integer k (0 ≤ k ≤ 10^5).
Output:
Print 'true' if the condition is satisfied, otherwise 'false'.
Example:
Input:
1 2 3 1
3
Output:
true
Key concepts
sliding_windowhash_maparrays
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now