Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 12 (value 9): left 17, right 66; node 17 (value 0): left 69, right none; node 48 (value -6): left none, right none; node 55 (value 2): left none, right 48; node 66 (value 1): left none, right none; node 69 (value -4): left none, right 87; node 76 (value -7): left 55, right 12; node 87 (value -5): 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. 3
  2. B. 9
  3. C. 5
  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