Longest Univalue Path
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given the root of a binary tree, return the length of the longest path in which every node has the same value.
A path is any sequence of nodes connected by parent-child edges, with no node repeated. It does not have to pass through the root, and it may go up through a node and back down the other side. The length of a path is its number of **edges**.
An empty tree or a single node has answer 0.
Examples
Constraints
- 0 <= number of nodes <= 10^4
- -1000 <= Node.val <= 1000
- The depth of the tree is at most 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.