Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
K Closest Points to Origin
Bookmark
Sort by Distance
Max-Heap of Size K
Quickselect
Input
Small (k=2)
Medium (k=3)
Two points (k=1)
Equal distance
Custom
points
=
[[1,3],[-2,2],[5,8],[0,1],[-3,-1]]
,
k
=
2
[1,3]
[-2,2]
[5,8]
[0,1]
[-3,-1]
points by distance
[1,3]
d²=10
[-2,2]
d²=8
[5,8]
d²=89
[0,1]
d²=1
[-3,-1]
d²=10
[1,3]
[-2,2]
[5,8]
[0,1]
[-3,-1]
points by distance
[1,3]
d²=10
[-2,2]
d²=8
[5,8]
d²=89
[0,1]
d²=1
[-3,-1]
d²=10
[1,3]
[-2,2]
[5,8]
[0,1]
[-3,-1]
points by distance
[0,1]
d²=1
[-2,2]
d²=8
[1,3]
d²=10
[-3,-1]
d²=10
[5,8]
d²=89
[1,3]
[-2,2]
[5,8]
[0,1]
[-3,-1]
points by distance
[0,1]
d²=1
[-2,2]
d²=8
[1,3]
d²=10
[-3,-1]
d²=10
[5,8]
d²=89
[1,3]
[-2,2]
[5,8]
[0,1]
[-3,-1]
points by distance
[0,1]
d²=1
[-2,2]
d²=8
[1,3]
d²=10
[-3,-1]
d²=10
[5,8]
d²=89
algo
master
.
io
Step:
Find the 2 closest of 5 points to the origin
0 / 3
Input
Small (k=2)
Medium (k=3)
Two points (k=1)
Equal distance
Custom
points
=
[[1,3],[-2,2],[5,8],[0,1],[-3,-1]]
,
k
=
2
0 / 3
algo
master
.
io
Step:
Find the 2 closest of 5 points to the origin