Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

In how many ways can a set of 6 distinct people be partitioned into groups so that every group has an even number of people (groups are unordered)?

  1. A. 41
  2. B. 16
  3. C. 32
  4. D. 31

Correct answer: D. 31

A bitmask recursion picks the block containing the lowest unassigned person and recurses on the rest, counting only blocks of even size. The block shapes 2+2+2, 4+2 and 6 contribute 15 + 15 + 1 = 31, while the total number of set partitions of 6 people is 203.

More Coding Interview Problems questions

Exams that ask this topic