Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many arrays of length 4 with entries from {0, 1, 2} have an EVEN total sum?

  1. A. 46
  2. B. 41
  3. C. 40
  4. D. 42

Correct answer: B. 41

Track the parity of the running sum: each entry from {0, 1, 2} contributes its parity to the state, and an even final parity is counted by a two-state DP. Taking exactly half of the 81 arrays ignores that the parity counts are not equal here.

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

Exams that ask this topic