Skip to content

1552. Magnetic Force Between Two Balls #287

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the maximum possible minimum magnetic force between any two balls placed in baskets at given positions. The magnetic force between two balls at positions x and y is defined as |x - y|. The goal is to distribute m balls such that the minimum magnetic force between any two balls is maximized.

Approach

  1. Sort the Positions: First, sort the array of basket positions to facilitate checking distances between consecutive baskets.
  2. Binary Search on Distance: Use binary search to find the maximum possible minimum distance. The search range starts from 0 to the maximum possible distance between the first and last basket.
  3. Check Feasibility: For each midpoint distance during the bi…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz May 17, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim May 17, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants