Search
⌘K

Leetcode 687. Longest Univalue Path

Given a binary tree, find the length (number of edges) of the longest path whose nodes all share the same value, where the path may lie anywhere in the tree. This is solved by a DFS that for each node computes the longest same-valued descending path into its children and combines left/right contributions to update the global maximum.

Asked at:

Meta


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Early October, 2025

Meta

Mid-level

Comments

Your account is free and you can post anonymously if you choose.