Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Count the subsets of [3, 1, 4, 2, 6, 4] whose sum is exactly half the total sum (the subset may be any size; the empty subset is counted only if the total is 0).
- A. 6
- B. 3
- C. 64
- D. 12
Correct answer: A. 6
The total is 20, so count subsets with sum 10 by a subset-sum DP (or 64 bitmasks): 6, the two 4s being different positions. Counting each split {S, complement} once gives 3, 64 counts every subset, and counting each subset together with its complement again gives 12.
More Coding Interview Problems questions
- Problem: Count the longest increasing subsequences (subsequences of maximum length, strictly increasing) of [1, 3, 5, 4, 7]. Two index…
- Problem: Snakes and ladders on squares 1–30: from square s, a die roll of r moves you to s + r (for 1 ≤ r ≤ 6, if s + r ≤ 30). Ladders…
- Problem: Nim with three piles of sizes 1, 2 and 3. A move removes any positive number of stones from one pile. The player who takes the…
- Problem: How many subarrays of [1, 2, 3, 0, 3, 2, 1] have a XOR of zero?
- Problem: How many integers from 1 to 50 have exactly two 1-bits in their binary representation?
- Problem: What is the sum of the decimal digits of 9⁹?