Data Structures & AlgorithmsHard

Five people weigh 3 5 3 4 2. Each boat holds at most two people and its total weight must not exceed 7. What is the minimum number of boats needed to carry everyone?

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

Correct answer: A. 3

Sort the weights and pair the heaviest person with the lightest one that fits, a two-pointer greedy that is optimal for at most two per boat. Sending one person per boat ignores pairing, and the sum-divided bound ignores the weight limit per boat.

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

Exams that ask this topic