Back to problems

Binary Tree Longest Consecutive Sequence II

Algorithm · Uber · Hard

Given the root node of a binary tree, determine the maximum length of any consecutive path within the tree. A path is consecutive when every neighboring pair of nodes has values that differ by exactly one. Its values may rise or fall from one node to the next. For instance, [5,6,7,8] and [8,7,6,5] qualify as consecutive paths, whereas [5,6,8,7] does not. The path may travel from a child through its parent and then to another child, so it is not restricted to one downward…

Checking your access…