Find the Longest Consecutive Path in a Binary Tree
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
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:
```python
def longest_downward_consecutive_path(root) -> int:
pass
```
Quick Answer: 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 serialized binary tree `[val,left,right]`, return the longest downward parent-to-child path where values increase by one.
Examples
Input: ([1,[2,None,None],[3,None,None]],)
Expected Output: 2
Explanation: 1->2 or 1->3? only 1->2.
Input: (None,)
Expected Output: 0
Explanation: Empty.