Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 2 (value -7): left none, right none; node 9 (value 7): left 34, right 39; node 34 (value -5): left 80, right none; node 39 (value -7): left 93, right none; node 44 (value 9): left none, right none; node 45 (value 2): left none, right none; node 69 (value -4): left 89, right 9; node 80 (value 7): left none, right 2; node 83 (value 9): left none, right 45; node 89 (value -7): left none, right none; node 93 (value -6): left none, right 44; node 96 (value -9): left 83, right 69. A path is any sequence of nodes in which consecutive nodes are joined by an edge, with no node repeated; a single node is a path. The value of a path is the sum of its node values. What is the maximum value of any path?

  1. A. 2
  2. B. 11
  3. C. 9
  4. D. 7

Correct answer: B. 11

The best path may bend at any node, start and end anywhere, and can be a single node. Restricting it to start at the root, to be one node, or to pass through the root gives smaller values.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic