Data Structures & AlgorithmsVery hard

From 4 9 1 7 3 8 2, choose positions so that no two CHOSEN positions are adjacent in the array. What is the maximum possible sum of the chosen values?

  1. A. 34
  2. B. 25
  3. C. 24
  4. D. 23

Correct answer: C. 24

Use a DP that keeps the best sum ending with or without the current element; brute force over subsets confirms the value. Choosing the global maximum plus its best non-adjacent partner, or dropping the smallest chosen value, misses optimal selections.

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

Exams that ask this topic