Data Structures & AlgorithmsModerateTCS NQT · CAT · MBA placement

A truck carries at most 5 boxes. Box types are given as (number of boxes of this type, units per box): [(1, 3), (2, 2), (3, 1), (2, 4)]. What is the maximum number of units you can load?

  1. A. 9
  2. B. 14
  3. C. 16
  4. D. 15

Correct answer: D. 15

Load boxes in decreasing order of units per box, taking as many of each type as the remaining capacity allows. Taking types in the order listed leaves more valuable boxes behind.

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

Exams that ask this topic