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)?
- A. 41
- B. 16
- C. 32
- 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
- From the values [3, 5, 6, 7, 10], choose any non-empty subset and XOR its elements together. What is the largest value that can be obtained?
- Four groups are G1 = {1, 4}, G2 = {2, 9}, G3 = {3, 7} and G4 = {5, 6}. Choosing exactly one element from each group, how many choices sum…
- Using each of the values 1, 2, 5, 9 and 20 at most once, which is the smallest positive integer that CANNOT be written as the sum of some…
- Half-open segments [1,4), [3,7), [6,10), [9,12), [2,5), [8,11) are given. Choose pairwise disjoint segments to maximise the total length…
- Closed intervals [0,3], [2,5], [4,8], [6,9], [8,12] are available. What is the minimum number of them needed so that every point of the…
- Closed intervals [1,6], [4,10], [5,5], [8,12], [2,3] are given. For the query points 5, 9 and 1, count how many intervals contain each…