LC: Binary Tree Longest Consecutive Sequence II - spiralgo/algorithms GitHub Wiki

Binary Tree Longest Consecutive Sequence II

The Essence:

If both children of the path provide an increasing or decreasing path, the maximum of these 2 should be taken. The other sequence decreasing/increasing can then be assumed 0. The length of the consecutive sequence at each node is then can be given by the equation: increasing+decreasing+1. For this, child nodes needs to return their increasing sequence lengths, or decreasing sequence lengths.

Details:

It's to be noted that the traversal here is done in "post-order", "left-right-root".

Further details and implementation can be found here: https://github.com/spiralgo/algorithms/pull/312