Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Weights [2, 3, 3, 4, 1, 2] are packed into boxes of capacity 5 by first-fit decreasing. How many boxes are used?

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

Correct answer: D. 3

The total weight is 15, so at least 3 boxes are needed, and first-fit decreasing achieves 3 here by pairing 4 with 1 and 3 with 2, and 3 with 2.

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

Exams that ask this topic