Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional
How many non-empty subsets of {1, 2, 3, 4, 5, 6, 7} have a bitwise AND of their elements equal to 0?
- A. 93
- B. 88
- C. 37
- D. 90
Correct answer: D. 90
For a non-empty subset the AND is zero when every bit position is cleared by some element; a DP over the 3 bit positions with a mask of which bits are still set counts these. The complement 127 - count is a different count, which is the trap.
More Coding Interview Problems questions
- Lists L1 = {1, 4, 7}, L2 = {2, 5, 8} and L3 = {3, 6, 9}. Choosing one element from each list, how many choices give a total of 15?
- From the values [12, 3, 9, 15, 6, 20, 10, 7], choose 3 of them. What is the smallest possible difference between the largest and the…
- Meetings (start, end) are (1,2), (3,4), (0,6), (5,7), (8,9), (5,9). A room hosts one meeting at a time, and a meeting may start exactly…
- Array [4, 7, 1, 9, 3, 6, 2, 5]. How many pairs of prefix indices (i < j) among the nine prefix sums (including the empty prefix) have a…
- How many integers x with 1 <= x <= 100 are divisible by 3 and have exactly two 1-bits in their binary representation?
- Positive array [2, 7, 1, 8, 3, 4, 6]. What is the largest possible sum of a contiguous subarray that does not exceed 15?