1552. Magnetic Force Between Two Balls / Aggressive Cows
Problem Statement
In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n
empty baskets, the ith
basket is at position[i]
, Morty has m
balls and needs to distribute the balls into the baskets such that the minimum magnetic force between any two balls is maximum.
Rick stated that magnetic force between two different balls at positions x
and y
is |x - y|
.
Given the integer array position
and the integer m
. Return the required force.
Example 1:
Example 2:
Constraints:
n == position.length
2 <= n <= 105
1 <= position[i] <= 109
All integers in
position
are distinct.2 <= m <= position.length
Intuition
Links
https://leetcode.com/problems/magnetic-force-between-two-balls/description/
Video Links
https://www.youtube.com/watch?v=R_Mfw4ew-Vo&ab_channel=takeUforward
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated