Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

From the eight distinct values [4, 9, 11, 2, 7, 13, 5, 8], how many 4-element subsets sum to exactly 20? Use meet in the middle on the two halves of the sorted list.

  1. A. 5
  2. B. 3
  3. C. 2
  4. D. 1

Correct answer: D. 1

Split the eight values into halves and enumerate all subsets of each half with their sizes. Matching a subset of size i from one half with a subset of size 4 - i from the other half gives every 4-element subset exactly once.

More Coding Interview Problems questions

Exams that ask this topic