You are given a binary tree consisting of N nodes. Every node contains an integer value (which may be negative).
A route is any sequence of connected nodes. The route may start and end at any two nodes, but each node can appear at most once.
The value of a route is the sum of the values of all nodes on it.
Find the maximum possible route value.
N value1 left1 right1 value2 left2 right2 ... valueN leftN rightN
Node 1 is the root.
Print the maximum route sum.
Expert in Data Structures & Algorithms. Building tools to help developers crack FAANG interviews.