Problem
Ask
Submissions

Problem: Magnetic Force Between Two Balls

Medium
30 min
Understand how to solve placement problems involving magnetic forces by using sorting and search algorithms. This lesson helps you learn how to distribute balls in baskets to maximize the minimum distance between them, reinforcing key concepts like binary search and two-pointer strategies for efficient coding interview solutions.

Statement

In the universe Earth C-137, Rick has discovered a unique type of magnetic force between two balls when placed in his newly invented baskets. He has nn baskets, each located at specific positions given by the array position[i]. Morty has m balls and needs to distribute these balls across the baskets in such a way that the minimum magnetic force between any two balls is as large as possible.

The magnetic force between two balls placed at positions xx and yy is calculated as the absolute difference xy|x−y|.

Given an integer array position and the number of balls m, return the maximum possible value of the minimum magnetic force between any two balls after they have been placed in the baskets.

Constraints:

  • 22 \leq position.length 103\leq 10^3

  • 11 \leq position[i] 104\leq 10^4

  • All integers in position are unique.

  • 22 \leq m \leq position.length

Problem
Ask
Submissions

Problem: Magnetic Force Between Two Balls

Medium
30 min
Understand how to solve placement problems involving magnetic forces by using sorting and search algorithms. This lesson helps you learn how to distribute balls in baskets to maximize the minimum distance between them, reinforcing key concepts like binary search and two-pointer strategies for efficient coding interview solutions.

Statement

In the universe Earth C-137, Rick has discovered a unique type of magnetic force between two balls when placed in his newly invented baskets. He has nn baskets, each located at specific positions given by the array position[i]. Morty has m balls and needs to distribute these balls across the baskets in such a way that the minimum magnetic force between any two balls is as large as possible.

The magnetic force between two balls placed at positions xx and yy is calculated as the absolute difference xy|x−y|.

Given an integer array position and the number of balls m, return the maximum possible value of the minimum magnetic force between any two balls after they have been placed in the baskets.

Constraints:

  • 22 \leq position.length 103\leq 10^3

  • 11 \leq position[i] 104\leq 10^4

  • All integers in position are unique.

  • 22 \leq m \leq position.length