Google | Onsite | Erase nodes in a Tree and return Forest of Trees

You are given a binary tree and a function shouldBeErased(node to check whether a node should be erased). Erase all nodes that should be erased in the binary tree and return the resulting forest in the form of an array of every root node.

	               A
				/      \
			 [B]        C
		   /      \         \
	     P          Q         R
		/    \
	E       [ M]
	
	Assume Nodes B and M can be deleted in a Tree
	
	
	The result is a list of TreeNodes [A,        P,        Q]
	                                  /   \     /
									  null C   E
											 \
											  R

https://leetcode.com/problems/delete-nodes-and-return-forest

Comments (6)