Data Structures & AlgorithmsModerateTCS NQT · Infosys

People weigh [3, 5, 3, 4, 2, 7, 1] kg. Each boat carries at most two people and at most 9 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

Sort the weights and pair the heaviest remaining person with the lightest one when they fit within the limit, otherwise the heaviest goes alone. Pairing in arrival order or greedily matching the heaviest with the next heaviest fails.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic