Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

Choose a subsequence of [4, 7, 2, 9, 5, 6, 1] with no two chosen positions adjacent, such that its total is ODD. What is the largest such total?

  1. A. 17
  2. B. 23
  3. C. 19
  4. D. 20

Correct answer: C. 19

Use a DP with a parity state: taking index i forces skipping i+1, and the parity of the running total is tracked alongside the best sum. Taking the maximum non-adjacent sum and then fixing parity can lose the optimal odd sum.

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

Exams that ask this topic