Data Structures & AlgorithmsHardTCS NQT · Product Company SDE
Problem: Find the number of ways to select a non-empty subset of {1, 2, 4, 8, 16} whose sum is a multiple of 5.
- A. 6
- B. 7
- C. 3
- D. 31
Correct answer: A. 6
All 31 subset sums 1..31 are distinct, and exactly the multiples 5, 10, 15, 20, 25, 30 appear, so 6. Including the empty set gives 7, checking only singletons and pairs gives 3, and 31 counts every subset.
More Coding Interview Problems questions
- Problem: In the array [3, 5, 2, 8, 6, 1], the number of elements that are greater than every element after them (right leaders) is…
- Problem: A monotone sequence is built: start with 1, and append the next number as (previous number) + (number of digits of previous…
- Problem: The numbers 1 to 20 are split into odd numbers and even numbers. What is the absolute difference between the sum of the odd…
- Problem: A string of length 5 uses the letters x, y, z. How many such strings contain each of the three letters at least once?
- Problem: The array [5, 3, 8, 6, 2, 7] is processed by the partition step of quicksort with pivot = first element (5), using the…
- Problem: Starting with the number 100, subtract the square of the smallest prime factor of the current number each step (the number is…