less than 1 minute read

Given a binary tree root, return the longest path consisting of even values between any two nodes in the tree.

Constraints

  • n ≤ 100,000 where n is the number of nodes in root

https://binarysearch.com/problems/Longest-Even-Value-Path

Examples

Example 1

Input

  • root =

Output

  • answer = 5

Explanation

A longest path is [8, 0, 2, 6, 4]

Example 2

Input

  • root =

Output

  • answer = 4

Explanation

A longest path is [0, 2, 8, 4].

Solution

Leave a comment