FastPrepAll Cousins of a Tree Node
Problems/All Cousins of a Tree Node

All Cousins of a Tree Node

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem lists the cousins of one node in a binary tree: the other nodes on its level whose parent is a different node. An entry for an SDE role in Noida, India (a copy of a review, interview in November 2023, offer accepted) gives this as its only listed question. It came from an easy interview that covered data structures with a focus on trees and went over the resume. The entry does not define a cousin, and it gives no output form, limits or examples.

Our choices: a cousin is any node on the same level with a different parent, not only a child of the parent's sibling. The cousins are returned left to right. Node values are distinct numbers from 1 to 10^4, so the target is given by its value. Trees have 1 to 1000 nodes. The examples are new.

Our version is about 85% the same as the reported question.

Given the root of a binary tree and the value target of one of its nodes, return the values of that node's cousins.

A cousin is a node on the same level as the target node (the same number of steps from the root) whose parent is different from the target's parent. The target itself and its sibling are not cousins. Return the cousins from left to right as they appear on their level. If there are none (for example when the target is the root), return an empty list.

Function

cousinValues(root: TreeNode, target: int) → List<Integer>

Examples

Example 1

root = [11,4,9,2,7,5,13]target = 7return = [5,13]
root
114279513

Node 7 is on the third level with parent 4. The other nodes on that level are 2 (also a child of 4, so a sibling, not a cousin), 5 and 13 (children of 9). Answer, left to right: [5,13].

Example 2

root = [10,20,30]target = 20return = []
root
102030

Node 20's only other node on its level is 30, its sibling. Siblings are not cousins, so the answer is empty.

Example 3

root = [8,3,9,1,null,null,4,null,2,null,6]target = 2return = [6]
root
8312946

Node 2 is on the fourth level with parent 1; node 6 is on the same level with parent 4. The parents 1 and 4 are not siblings themselves (their parents are 3 and 9), but a cousin only needs the same level and a different parent. Answer: [6].

Constraints

  • The tree has between 1 and 1000 nodes.
  • 1 <= node.val <= 10^4, and all node values are different
  • target is the value of a node in the tree

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Maximum-Scoring Consecutive Tree LevelsJane Street · PHONE SCREENJane Street interview questions
  • Minimum Edits to a Perfect Binary TreeSnowflake · PHONE SCREENSnowflake interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Binary Tree Spiral Level OrderAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Check a Complete Binary TreeGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Binary Tree Right Side ViewGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Same Binary TreeOdoo · PHONE SCREENOdoo interview questions
  • Binary Tree Zigzag Level Order TraversalLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
  • Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
  • Bottom View of a Binary TreeOracle · PHONE SCREEN · ONSITE INTERVIEWOracle interview questions

Interview reports that mention this question

  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public List<Integer> cousinValues(TreeNode root, int target) {
        // Write your code here.
    }
}
Checking account…