Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Seven people weigh [3, 5, 3, 4, 2, 6, 1] (kg). A boat carries at most two people and at most 7 kg in total. What is the minimum number of boats needed to carry everyone?

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

Correct answer: A. 4

Pair the heaviest remaining person with the lightest one whenever the pair fits, otherwise send the heaviest alone. Two pointers on the sorted list achieve this in linear time, and the greedy count equals the brute-force minimum.

More Coding Interview Problems questions

Exams that ask this topic