GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Ten houses stand in a CIRCLE with values 6, 2, 9, 4, 3, 8, 1, 7, 5, 10 (the first and last houses are neighbours). No two neighbouring houses may both be chosen. What is the maximum total value?

  1. A. 40
  2. B. 30
  3. C. 34
  4. D. 36

Correct answer: C. 34

Because houses 1 and 10 are adjacent, solve the linear problem twice: on houses 2–10 and on houses 1–9, and take the larger. These give 34 (e.g. 9+8+7+10) and 30, so the answer is 34. The plain linear answer 40 (taking both 6 and 10, e.g. 6+9+8+7+10) is illegal on a circle.

More Algorithms questions

Exams that ask this topic