Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

Each number in [1, 2, 3, 4, 5, 6, 7] gets a sign '+' or '-', and all are then added. How many sign choices give a total of exactly 4?

  1. A. 8
  2. B. 128
  3. C. 2
  4. D. 4

Correct answer: A. 8

Signing numbers so the total is T means choosing a subset P with sum (total + T)/2 to be positive. So the answer is the number of subsets with that sum, which is a subset-sum count rather than a choice of 2ⁿ sign patterns.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic