Tap here to switch tabs
Problem
Submissions

Problem: Binary Tree Longest Consecutive Sequence II

Try to solve the Binary Tree Longest Consecutive Sequence II problem.

Statement

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

A consecutive sequence path is defined as a path where the values of adjacent nodes in the sequence differ by exactly 11. The sequence may be increasing or decreasing, meaning paths such as [1,2,3,4][1, 2, 3, 4] and [4,3,2,1][4, 3, 2, 1] are both valid.

The path can move along parent and child connections in any valid route (such as from a child to a parent to another child), but it cannot split into more than two branches at any node.

Constraints:

  • The number of nodes in the tree is in the range [1,3imes104][1, 3 imes 10^4].

  • −3imes104≤-3 imes 10^4 \leq Node.val ≤3imes104\leq 3 imes 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Binary Tree Longest Consecutive Sequence II

Try to solve the Binary Tree Longest Consecutive Sequence II problem.

Statement

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

A consecutive sequence path is defined as a path where the values of adjacent nodes in the sequence differ by exactly 11. The sequence may be increasing or decreasing, meaning paths such as [1,2,3,4][1, 2, 3, 4] and [4,3,2,1][4, 3, 2, 1] are both valid.

The path can move along parent and child connections in any valid route (such as from a child to a parent to another child), but it cannot split into more than two branches at any node.

Constraints:

  • The number of nodes in the tree is in the range [1,3imes104][1, 3 imes 10^4].

  • −3imes104≤-3 imes 10^4 \leq Node.val ≤3imes104\leq 3 imes 10^4