Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 6 (value -6): left none, right none; node 23 (value -4): left 89, right none; node 29 (value 0): left none, right none; node 32 (value 8): left 98, right 29; node 34 (value 6): left none, right 23; node 77 (value -1): left 32, right none; node 89 (value 6): left none, right none; node 95 (value 2): left 6, right 34; node 97 (value -8): left 77, right 95; node 98 (value 0): left none, right none. 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. 8
  3. C. 9
  4. D. 10

Correct answer: D. 10

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