Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

The universe {0, ..., 5} must be covered by a union of chosen sets from {0,1,2}, {2,3}, {3,4,5}, {0,4}, {1,5}. What is the minimum number of sets needed?

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

Correct answer: D. 2

Checking subsets of the sets by size shows two sets suffice: {0,1,2} and {3,4,5} together cover everything. Choosing sets greedily by size or by the first uncovered element can pick a set that leaves a gap needing an extra set.

More Coding Interview Problems questions

Exams that ask this topic