Flip Equivalent Binary Trees

Understand and solve the interview question "Flip Equivalent Binary Trees".


Let’s start by defining what a flip operation for a binary tree is. We can define it as:

“Choosing any node and swapping the right and left child subtrees.”

A binary tree, T, is flip equivalent to another binary tree, S, if we can make T equal to S after some number of flip operations.

Given the roots of two binary trees, root1 and root2, you have to find out whether the trees are flip equivalent to each other or not. The flip_equiv function should return true if the binary trees are equivalent. Otherwise, it will return false.


Let’s look at the example below:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.