Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: Children with greed factors g = [1, 2, 3] and cookies s = [1, 1] (each child takes at most one cookie, and a cookie of size ≥ the greed factor satisfies the child). What is the maximum number of children that can be satisfied?

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

Correct answer: A. 1

Sort both lists and match the smallest sufficient cookie to the least greedy child who is not yet satisfied. Matching the largest cookies to the greediest children satisfies fewer.

More Coding Interview Problems questions

Exams that ask this topic