Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Choose any subset (empty allowed) of {1, 2, 3, 4, 5}. How many subsets have bitwise OR equal to 7?
- A. 16
- B. 21
- C. 18
- D. 17
Correct answer: D. 17
Track the number of subsets achieving each OR value over the 3-bit range with a DP that adds one element at a time, taking OR instead of sum. Subsets whose OR is 7 must contain an element with bit 4 set; counting by plain sums is a different count.
More Coding Interview Problems questions
- How many binary strings of length 8 contain no three consecutive 1s?
- Array [5, 2, 8, 1, 4, 6, 3]. How many index pairs i < j have a[i] AND a[j] = 0 (no common set bit)?
- What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?
- Consider the eight primes 2, 3, 5, 7, 11, 13, 17, 19. How many subsets (including the empty subset, whose product is 1) have a product…
- How many 3-element subsets of {1, 2, 3, 4, 5, 6, 7, 8} have a sum divisible by 6?
- Half-open intervals [1,4), [2,6), [3,5), [5,8), [7,9), [8,10) are given. What is the largest number of them you can select so that no time…