Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Items [1, 1, 1, 1, 2, 2, 3] must be placed into stacks of capacity 3 such that each stack holds only identical items. What is the minimum number of stacks?

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

Correct answer: D. 4

Group identical values; each value with count c needs ceil(c / 3) stacks. Here value 1 needs 2, value 2 needs 1 and value 3 needs 1, totalling 4.

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

Exams that ask this topic