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?

  1. A. 16
  2. B. 21
  3. C. 18
  4. 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

Exams that ask this topic