Clone a Binary Tree
Medium Accuracy: 55.34% Submissions: 15227 Points: 4

Given a special binary tree having random pointers along with the usual left and right pointers. Clone the given tree.

Example 1:


Output: 1
Explanation: The tree was cloned successfully.

Your Task:
No need to read input or print anything. Complete the function cloneTree() which takes root of the given tree as input parameter and returns the root of the cloned tree. 

Note: The output is 1 if the tree is cloned successfully. Otherwise output is 0.

Expected Time Complexity: O(N).
Expected Auxiliary Space: O(N).

1 ≤ Number of nodes ≤ 100
1 ≤ Data of a node ≤ 1000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Clone a Binary Tree

Output Window