Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Contains Duplicate
Bookmark
Brute Force
Sorting
Hash Set
Input
Has Duplicate
No Duplicate
Immediate Duplicate
Custom
nums
=
[1, 2, 3, 1]
1
2
3
1
0
1
2
3
no map — compare every pair of elements
1
2
3
1
0
1
2
3
no map — compare every pair of elements
1
2
3
1
0
1
2
3
i
fix nums[0] = 1, compare with everything after it
1
2
3
1
0
1
2
3
i
j
nums[0] ≠ nums[1], keep scanning
1
2
3
1
0
1
2
3
i
j
nums[0] ≠ nums[2], keep scanning
duplicate
1
2
3
1
0
1
2
3
i
j
nums[0] == nums[3] — duplicate found
duplicate
1
2
3
1
0
1
2
3
i
j
return
true
duplicate
1
2
3
1
0
1
2
3
return
true
algo
master
.
io
Step:
Compare every pair of elements looking for a match
0 / 6
Input
Has Duplicate
No Duplicate
Immediate Duplicate
Custom
nums
=
[1, 2, 3, 1]
0 / 6
algo
master
.
io
Step:
Compare every pair of elements looking for a match