Challenge: Free Tree

Let’s empty a binary tree. We’ll also see how we can do it in one line.


Given a binary tree, free all its nodes.


A binary tree.


An empty tree.

Sample input

The root node t.root of a binary tree will be our input. We have to empty the tree.We’ll do this by using the freeTree() function.

Here’s the sample input tree t.

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