Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional

A binary tree has these nodes: node 4 (value 9): left 67, right 54; node 8 (value 1): left none, right 11; node 11 (value 9): left none, right none; node 14 (value -3): left none, right none; node 18 (value -8): left 55, right none; node 54 (value 5): left none, right none; node 55 (value 4): left 84, right none; node 67 (value -3): left none, right none; node 69 (value -9): left none, right none; node 75 (value -6): left 14, right 69; node 84 (value -5): left 75, right 4; node 94 (value -4): left 18, right 8. 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. 6
  2. B. 9
  3. C. 14
  4. D. 11

Correct answer: C. 14

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