EASYasked at 1 company

Cousins in Binary Tree

A easy-tier problem at 58% community acceptance, tagged with Tree, Depth-First Search, Breadth-First Search. Reported in interviews at Tekion and 0 others.

Founder's read

Cousins in Binary Tree is an easy-difficulty tree problem that shows up in live assessments at companies like Tekion. The trick is simple but the execution matters: two nodes are cousins if they're at the same depth but have different parents. Most candidates either overcomplicate it with multiple tree passes or mess up the parent-tracking logic. The 58% acceptance rate reflects how many people nail the concept but fail edge cases in the implementation. If you blank on the traversal order during your OA, StealthCoder runs invisibly and surfaces a working solution in seconds.

Companies asking
1
Difficulty
EASY
Acceptance
58%

Companies that ask "Cousins in Binary Tree"

If this hits your live OA

Cousins in Binary Tree 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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The standard approach uses either BFS or DFS to track both node depth and parent reference simultaneously. BFS is usually cleaner: queue nodes with their parents, track depths, find both target nodes in one pass, then compare. DFS works too but requires careful recursion logic to propagate parent pointers down the tree. The gotchas are forgetting to check the parent condition, losing track of which node is which during traversal, or queuing the same node twice. Most candidates try to find each node separately, burning an extra tree walk. The real win is doing it in a single traversal while keeping the parent in scope. If this problem hits your live assessment and the traversal pattern doesn't click, StealthCoder solves it without the proctor seeing anything.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Cousins in Binary Tree recycles across companies for a reason. It's easy-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. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Cousins in Binary Tree interview FAQ

What makes this easy but still 58% acceptance.+

The concept is obvious once explained, but implementation trips people up. Parent tracking in recursion is error-prone, and comparing node references (not values) confuses candidates. Edge cases like one node being the root or both nodes being the same also catch people who skip depth verification.

Is BFS or DFS better here.+

BFS is more intuitive. You process nodes level by level, so depth tracking is implicit. DFS works but requires explicit depth parameters and parent pointers in recursion. For this problem, BFS is faster to code and less prone to parent-reference bugs.

How do I track parents without breaking the tree structure.+

Don't modify the tree. Wrap each node in a tuple or object when you queue or recurse: (node, parent, depth). Store parent references separately. This keeps the tree immutable and makes it easy to compare parents later without side effects.

Does Tekion ask this frequently in their OAs.+

Tekion has reported this problem. Tree problems are common across their assessments. If it appears, it's usually early in the loop, so nailing it saves mental energy for harder problems later.

What if the two nodes are in different subtrees.+

That's fine. As long as they're at the same depth and have different parents, they're cousins. The algorithm doesn't care which subtree they're in. Your traversal will find both in one pass, then the comparison handles all cases automatically.

Want the actual problem statement? View "Cousins in Binary Tree" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.