Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
How many subsets (including the empty subset) of {1, 2, ..., 10} have a sum divisible by 3?
- A. 344
- B. 343
- C. 345
- D. 341
Correct answer: A. 344
Count by DP over the sum modulo 3: each element either skips or shifts the residue, starting at residue 0 for the empty set. Excluding the empty set is the usual mistake, since its sum 0 is divisible by 3.
More Coding Interview Problems questions
- 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] +…
- How many subsets of {1, 2, ..., 10} have a sum of exactly 10? The single-element subset {10} counts as one of them.
- A subset-sum question has n = 40 values. Splitting them into two halves of 20, how many subset sums must be enumerated for ONE half?
- Closed intervals [1,3], [3,5], [2,4], [5,7], [6,8] are given. Two intervals conflict if they share any point, endpoints included. What is…
- Meetings are the half-open intervals [0,30), [5,10), [15,20), [10,15), [20,25); a room can host a new meeting starting exactly when…