Back to problems

Tree Node Relationship — Sibling / Cousin / Other

Algorithm · Amazon · Easy

Examples Example 1 Example 2 Requirements Given a tree root and two node references (or node values), named a and b. Return sibling when they share a parent, cousin when they occupy the same level but have separate parents, and other for all remaining cases, including ancestor/descendant pairs and nodes at unequal depths. Because the prompt does not specify whether the tree is binary or n-ary, ask for that detail before implementation. Notes Mention these boundary conditions…

Checking your access…