Monday, December 14, 2015

Binary Tree Longest Consecutive Sequence

Q:
Given a binary tree, find the length of the longest consecutive sequence path.
The path refers to any sequence of nodes from some starting node to any node in the tree along the parent-child connections.
Note: The path does not need to go through the root.
For example,
   4
  / \
 1   3
    / \
   2   5
Longest consecutive sequence path is 2-3-4, so return 3.
   5
  / \
 2   3
    / \
   2   4
  / \
 3   1
Longest consecutive sequence path is 1-2-3-4, so return 4.
A:

Mistakes:





No comments:

Post a Comment