Longest Step-by-One Chain in a Tree

Asked at Google · Coding Questions · Difficulty: Medium · Last asked Jul 2, 2026

Every node of a binary tree holds an integer. A step-by-one chain is a sequence of tree nodes, each joined to the next by a tree edge, whose values go up by exactly 1 at every step (for example `4, 5, 6`). Find the longest such chain that only moves downward, from a parent to one of its children. The length of a chain is the number of nodes in it.

Loading the problem…