Magnetic Force Between Two Balls
MediumBinary Search
Decode it first. Clues, constraints, pattern and plan before any code.There are baskets at the positions in position (not necessarily sorted). You must place m balls into distinct baskets so that the minimum distance between any two balls is as large as possible. Return that largest possible minimum distance.
position = [1, 2, 3, 4, 7], m = 3 → 3 (balls at 1, 4, 7)
position = [5, 4, 3, 2, 1, 1000000000], m = 2 → 999999999
position = [1, 2], m = 2 → 1Constraints
2 <= position.length <= 10^51 <= position[i] <= 10^9- All values in
positionare distinct. 2 <= m <= position.length