Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

How many NON-EMPTY subsets of [4, 7, 2, 9, 5, 3, 8, 6] have a sum divisible by 3? Subsets are chosen by position.

  1. A. 88
  2. B. 87
  3. C. 85
  4. D. 1

Correct answer: B. 87

Track the count of subsets for each remainder mod 3: each new number either joins a subset (shifting its remainder) or not. Remember to remove the empty subset, which also has remainder 0.

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

Exams that ask this topic