Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

Children have greed factors [1, 2, 3] and cookies have sizes [1, 1]. A child is content if assigned a cookie of size at least their greed factor, and each child gets at most one cookie. What is the maximum number of content children?

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

Correct answer: D. 1

Sort both and match the smallest feasible cookie greedily. Only the greed-1 child can be satisfied with size-1 cookies, and the second cookie is too small for greed 2.

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

Exams that ask this topic