Find the Longest Consecutive Path in a Binary Tree
GoogleSoftware Engineer · OnsiteLast 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
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.