Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Contains Duplicate II
Bookmark
Brute Force
Hash Map
Sliding Window
Input
Within k
Too far
Adjacent
All distinct
Custom
nums
=
[1, 2, 3, 1]
,
k
=
3
1
2
3
1
0
1
2
3
test every pair that could be close enough to count
1
2
3
1
0
1
2
3
test every pair that could be close enough to count
k =
3
comparisons
0
j ≤ i + k = 3
1
2
3
1
0
1
2
3
i
i = 0, value
1
check j = 1 to 3
k =
3
comparisons
1
j ≤ i + k = 3
1
2
3
1
0
1
2
3
i
j
1
≠
2
nums[0] vs nums[1]
k =
3
comparisons
2
j ≤ i + k = 3
1
2
3
1
0
1
2
3
i
j
1
≠
3
nums[0] vs nums[2]
k =
3
comparisons
3
j ≤ i + k = 3
dist 3 ≤ 3
1
2
3
1
0
1
2
3
i
j
1
==
1
3 - 0 = 3 ≤ 3
k =
3
comparisons
3
dist 3 ≤ 3
1
2
3
1
0
1
2
3
return
true
algo
master
.
io
Step:
Check every pair no more than k = 3 apart, and stop at the first repeat
0 / 5
Input
Within k
Too far
Adjacent
All distinct
Custom
nums
=
[1, 2, 3, 1]
,
k
=
3
0 / 5
algo
master
.
io
Step:
Check every pair no more than k = 3 apart, and stop at the first repeat