Data Structures & AlgorithmsVery hard

What is the minimum number of elements you must DELETE from 7 4 9 2 5 8 so that the sum of the remaining elements is divisible by 6? (Deleting nothing is allowed if it already works.)

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

Correct answer: B. 1

The sum of the kept elements must hit residue 0 mod 6, so try deletion sets of increasing size and check the residue of what remains. Counting elements divisible by 6 ignores combinations, and the mod-3 answer is a weaker requirement.

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

Exams that ask this topic