Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
How many subsets (including the empty subset) of [3, 5, 9, 11, 14, 2] have a sum divisible by 7?
- A. 13
- B. 14
- C. 9
- D. 1
Correct answer: B. 14
A DP over sums mod 7 (or the 64 bitmasks) gives 14 subsets including the empty one. Excluding the empty set gives 13, assuming 64 / 7 ≈ 9 gives 9, and counting only sum exactly 7 gives 1 ({5, 2}).
More Coding Interview Problems questions
- Closed intervals [1,4], [2,6], [4,7], [5,9], [8,10] are given. What is the largest number of intervals that share a single integer point?
- Array [2, 8, 9, 18, 4, 16, 6, 3]. How many index pairs i < j have a[i] a[j] equal to a perfect square?
- Array [1, 2, 4, 3, 0, 5, 6]. What is the length of the longest contiguous subarray in which the XOR of the elements equals their sum?
- Ropes of lengths 4, 3, 2 and 6 are joined two at a time; joining ropes of lengths x and y costs x + y and creates one rope of length x +…
- Array [1, 2, 4, 1, 3, 4]. How many contiguous subarrays have a bitwise OR of exactly 7?
- Set A = {1, 2, 4, 7} and set B = {3, 5, 6, 8}. Choose two different elements from A and two different elements from B. How many choices…