Cousins in Binary Tree
Easy · Trees · about 10 minutes
Asked at Meta, Amazon, Google, Microsoft.
In a binary tree with unique values, two nodes are cousins if they are at the same depth but have different parents. Given values x and y of two different nodes in the tree, return true if they are cousins.