549. Binary Tree Longest Consecutive Sequence II

Given the root of a binary tree, return the length of the longest consecutive path in the tree.

A consecutive path is a simple path whose values are globally increasing by exactly 1 or globally decreasing by exactly 1 when read from one endpoint to the other. The path may run from a parent to a child or from a child to a parent, and may pass through a parent between two child subtrees. A change in value-difference sign is not allowed, so 1, 2, 3, 2 is not a valid full consecutive path.

The path does not need to start or end at the root or a leaf; it can be any path in the tree where values are consecutive.

Examples
Input: [1]
Output: 1
Hints

549. Binary Tree Longest Consecutive Sequence II

Given the root of a binary tree, return the length of the longest consecutive path in the tree.