Place K Driver Hubs on a Highway to Maximize Minimum Spacing

Last updated: November 29, 2026

Quick Overview

Given candidate mile markers along a highway and an integer k, choose k markers for driver rest hubs so that the smallest distance between any two chosen hubs is as large as possible. Return that largest possible minimum distance.

Uber
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given candidate mile markers along a highway and an integer k, choose k markers for driver rest hubs so that the smallest distance between any two chosen hubs is as large as possible. Return that largest possible minimum distance.

A technical screen problem in Uber loops that tests binary search on the answer with a greedy feasibility check. Interviewers look for the proof that greedy placement from the left is optimal for a given gap.

What the Interviewer Expects
  • Sorts the candidate positions
  • Writes a greedy check that places a hub whenever the gap is at least d
  • Explains why picking the leftmost feasible site is optimal
  • Binary searches d from 0 to the full span
  • States O(n log n + n log span) time
Key Topics to Cover
binary search on answer
greedy
sorting
maximize minimum
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return the chosen markers as well.
  • What if hubs also have a maximum allowed gap for coverage?
  • How does the problem change on a ring road?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of distinct integer positions, 2 <= k <= len(positions).
  • Output: the maximum achievable minimum gap.
  • Positions arrive unsorted....
High-Level Design

If we can place k hubs with minimum gap d, we can also do it with any smaller gap, so feasibility is monotone in d and we binary search for the largest feasible d. Check(d): sort positions, put the fi...


Submit Your Answer
Markdown supported