Longest Univalue Path
A medium-tier problem at 43% community acceptance, tagged with Tree, Depth-First Search, Binary Tree. Reported in interviews at Zepto and 2 others.
Longest Univalue Path is a medium-difficulty tree problem that asks you to find the longest path where every node has the same value. It's asked by Zepto, Sprinklr, and Snowflake, and has a 43% acceptance rate, which means most people who see it in a live assessment either misread the requirement or get tripped up on the traversal logic. The trick isn't complex once you see it, but you need to think about paths differently than you normally do in tree problems. If you blank on the approach mid-OA, StealthCoder delivers a working solution in seconds, invisible to the proctor.
Companies that ask "Longest Univalue Path"
Longest Univalue Path is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe naive mistake is trying to find the longest path by treating univalue paths like standard tree paths. Most candidates write DFS but forget that a 'path' doesn't have to go through the root or even be rooted at all. You need to count both downward paths from each node and combine them, but only if adjacent nodes share the same value. The actual solution uses post-order DFS: for each node, calculate the longest univalue path going down into its left and right subtrees, then combine them if the values align. The real complexity isn't the algorithm, it's remembering that you're tracking paths ending at each node, not starting from it. Edge cases like single-node paths and disconnected univalue regions trip up candidates who haven't built intuition here. StealthCoder handles the bookkeeping and indexing automatically if this pattern doesn't click during your assessment.
Pattern tags
You know the problem.
Make sure you actually pass it.
Longest Univalue Path recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Longest Univalue Path interview FAQ
Is this problem actually asked at Zepto, Sprinklr, and Snowflake?+
Yes. All three companies have reportedly asked it in their OAs or technical interviews. At 43% acceptance, it's a real filter, not a throwaway warm-up.
How does this differ from the longest path problems I've drilled?+
Standard longest path problems care about any path between two nodes. Univalue path is stricter: every single node on the path must have the same value. You can't skip or mix values. That constraint changes the entire traversal logic.
Why do so many people get this wrong in a live OA?+
The acceptance rate of 43% tells you most candidates misunderstand what counts as a valid path, or they implement DFS correctly but forget to check value equality between parent and child before extending the count.
Do I need to handle multiple test cases or just a single tree?+
The problem gives you one tree and asks for one answer. No loops or variations. The challenge is the single correct solution, not handling edge cases or scaling.
Is this still asked after being on LeetCode for years?+
Yes. The fact that Zepto, Sprinklr, and Snowflake still use it suggests it's a stable part of their interview loop. It's not trendy, just reliable.
Want the actual problem statement? View "Longest Univalue Path" on LeetCode →