Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Stalls at positions [1, 2, 4, 8, 9, 13] are available. Place 3 cows in distinct stalls so that the smallest distance between any two cows is as large as possible. What is that largest minimum distance?

  1. A. 6
  2. B. 4
  3. C. 8
  4. D. 5

Correct answer: D. 5

For a fixed minimum distance d, greedy placement from the left is optimal, so binary search over d with a feasibility check finds the largest d that still fits all cows.

More Coding Interview Problems questions

Exams that ask this topic