Challenge: Copy Tree

Let’s copy a binary tree.


Given a binary tree, copy its values to another binary tree.


A binary tree.


A new binary tree with the data of the given binary tree.

Sample input

The root node t.root of a binary tree will be our input, for which we have to generate a copy tree. We’ll generate this new tree by using the copyTree() function.

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