Search
⌘K

Leetcode 549. Binary Tree Longest Consecutive Sequence II

Find the length of the longest path in a binary tree where adjacent node values differ by exactly 1 (either increasing or decreasing), and the path may go up through a parent and down to a child (i.e., can combine increasing and decreasing segments through a node). This requires tree traversal to compute, for each node, the longest increasing and decreasing consecutive runs in its subtrees and combine them to get the global maximum.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Comments

Your account is free and you can post anonymously if you choose.