Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Max Points on a Line
Bookmark
Input
All collinear (3)
Mixed (result=4)
Two points (2)
Two lines
Custom
points
=
[[1,1],[2,2],[3,3]]
slopeMap
best = 0
collinear points through an anchor share the same slope
slopeMap
best = 0
collinear points through an anchor share the same slope
slopeMap · anchor p0
best = 2
reduce → slope
1/1
slopeMap · anchor p0
slope 1/1
×1
best = 2
to p2: dy = 2, dx = 2
slopeMap · anchor p0
slope 1/1
×2
best = 3
anchor p0 gives 3 points →
new global max 3
slopeMap · anchor p1
best = 3
reduce → slope
1/1
slopeMap · anchor p1
slope 1/1
×1
best = 3
reduce → slope
1/1
slopeMap · anchor p1
slope 1/1
×2
best = 3
global max stays 3
slopeMap · anchor p2
slope 1/1
×1
best = 3
slope
1/1
now has
1
other point
slopeMap · anchor p2
slope 1/1
×1
best = 3
reduce → slope
1/1
slopeMap
slope 1/1
×2
max points = 3
max points on a line =
3
algo
master
.
io
Step:
Find the most points on one line
0 / 32
Input
All collinear (3)
Mixed (result=4)
Two points (2)
Two lines
Custom
points
=
[[1,1],[2,2],[3,3]]
0 / 32
algo
master
.
io
Step:
Find the most points on one line