Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Magnetic Force Between Two Balls
Bookmark
Brute Force
Binary Search on Answer
Input
Example 1
Example 2
Spread out
Evenly spaced
Multiples of 10
Custom
position
=
[1, 2, 3, 4, 7]
,
m
=
3
0
1
1
2
2
3
3
4
4
7
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Place ball 1 at position 1. count=1
0
1
1
2
2
3
3
4
4
7
Distance 3 >= 3. Place ball 2 at 4. count=2
0
1
1
2
2
3
3
4
4
7
d=3
Maximum minimum distance = 3
0
1
1
2
2
3
3
4
4
7
algo
master
.
io
Step:
Sort positions: [1, 2, 3, 4, 7]. Place 3 balls to maximize minimum distance.
0 / 47
Input
Example 1
Example 2
Spread out
Evenly spaced
Multiples of 10
Custom
position
=
[1, 2, 3, 4, 7]
,
m
=
3
0 / 47
algo
master
.
io
Step:
Sort positions: [1, 2, 3, 4, 7]. Place 3 balls to maximize minimum distance.