Katkat

Find the Longest Consecutive Path in a Binary Tree

GoogleSoftware Engineer · Onsite

Last updated

Practice a Google coding interview problem focused on find the longest consecutive path in a binary tree. The prompt emphasizes edge cases, clean implementation, and verifiable test behavior without revealing the solution.

Given a binary tree, return the length of the longest downward path where each child value is exactly one greater than its parent value. Nodes have val, left, and right.

Implement:

def longest_downward_consecutive_path(root) -> int:
 pass