Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
How many subsets of {1, 2, 3, ..., 12} have XOR equal to 0? The empty subset counts, because its XOR is 0.
- A. 256
- B. 255
- C. 260
- D. 128
Correct answer: A. 256
Track the count of each achievable XOR value with a DP over the elements, where each element joins or skips the subset. The empty subset is one of the counted subsets, so dropping it gives the off-by-one trap.
More Coding Interview Problems questions
- How many binary strings of length 10 contain no two adjacent 1s?
- In how many ways can a 3 x 4 grid be covered completely by non-overlapping 1 x 2 dominoes (each domino covers two adjacent cells, in…
- 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…
- How many subsets (including the empty subset) of {1, 2, ..., 10} have a sum divisible by 3?
- From the values [3, 34, 4, 12, 5, 2, 19, 8], choose any subset (the empty subset allowed). What is the smallest possible value of |(sum of…
- Arrays A = [1, 2], B = [-2, -1], C = [-1, 2] and D = [0, 2] each have two entries. How many index quadruples (i, j, k, l) satisfy A[i] +…