FastPrepMaximize the Minimum Distance Between Robots
Problems/Maximize the Minimum Distance Between Robots

Maximize the Minimum Distance Between Robots

Amazon logoAmazon● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Amazon Experience 32 describes an onsite Aggressive Cows variant in which robots are placed along a factory line. The source confirms the maximize-minimum-distance objective and binary-search optimization; the callable names and numeric bounds below are deterministic practice details. Core-task fidelity is about 97%.

A factory line has candidate robot stations at the distinct integer coordinates in positions. Choose exactly robots stations.

The separation of a placement is the minimum absolute distance between any two selected stations. Return the largest separation that can be achieved.

Function

maximizeMinimumRobotDistance(positions: int[], robots: int) → int

Examples

Example 1

positions = [1,2,8,12,17]robots = 3return = 7

Stations 1, 8, and 17 give adjacent gaps 7 and 9, so the minimum is 7.

Example 2

positions = [5,9]robots = 2return = 4

Both stations must be selected, and their distance is 4.

Example 3

positions = [0,3,4,7,10]robots = 4return = 3

Selecting 0, 3, 7, and 10 achieves a minimum gap of 3.

Constraints

  • 2 <= positions.length <= 100000.
  • 2 <= robots <= positions.length.
  • 0 <= positions[i] <= 10^9.
  • All positions are distinct.

More Amazon problems

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
  • 3SumPHONE SCREEN · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int maximizeMinimumRobotDistance(int[] positions, int robots) {
      // write your code here
    }
}
Checking account…