Data Structures & AlgorithmsHardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 3 (value -9): left none, right 34; node 5 (value 2): left none, right none; node 13 (value -6): left 16, right 3; node 16 (value 6): left 38, right none; node 34 (value 8): left none, right 53; node 38 (value -4): left 5, right 41; node 41 (value 5): left none, right none; node 53 (value 1): left 98, right none; node 98 (value 2): 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. 11
  2. B. 1
  3. C. 8
  4. D. 3

Correct answer: A. 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