Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Contains Duplicate III
Bookmark
Brute Force
Sorted Set
Bucket Sort
Input
Found (same value)
Not found
Custom
nums
=
[1, 2, 3, 1]
,
indexDiff
=
3
,
valueDiff
=
0
INPUT ARRAY
1
0
2
1
3
2
1
3
check every pair within indexDiff of each other
INPUT ARRAY
1
0
2
1
3
2
1
3
check every pair within indexDiff of each other
INPUT ARRAY
1
0
2
1
3
2
1
3
i
j − i ≤ 3
anchor at i =
0
, then scan forward
INPUT ARRAY
1
0
2
1
3
2
1
3
i
j
j − i ≤ 3
VALUE DISTANCE
|
1
−
2
| =
1
>
0
compare nums[
0
] with nums[
1
]
INPUT ARRAY
1
0
2
1
3
2
1
3
i
j
j − i ≤ 3
VALUE DISTANCE
|
1
−
3
| =
2
>
0
compare nums[
0
] with nums[
2
]
INPUT ARRAY
1
0
2
1
3
2
1
3
i
j
j − i ≤ 3
VALUE DISTANCE
|
1
−
1
| =
0
≤
0
compare nums[
0
] with nums[
3
]
INPUT ARRAY
1
0
2
1
3
2
1
3
i
j
j − i ≤ 3
VALUE DISTANCE
|
1
−
1
| =
0
≤
0
return true
algo
master
.
io
Step:
Compare every pair no more than 3 indices apart
0 / 5
Input
Found (same value)
Not found
Custom
nums
=
[1, 2, 3, 1]
,
indexDiff
=
3
,
valueDiff
=
0
0 / 5
algo
master
.
io
Step:
Compare every pair no more than 3 indices apart