...

/

Solution: Delete Nodes And Return Forest

Solution: Delete Nodes And Return Forest

Let’s solve the Delete Nodes And Return Forest problem using the Tree Depth-first Search pattern.

Statement

Given the root of a binary tree where each node has a unique value, your task is to delete all nodes with values specified in the deleteNodes array. After performing the deletions, the tree will split into a forest—a collection of disjoint trees. Return the roots of the remaining trees in the forest in any order.

Constraints:

  • 00\leq nodes 100\leq100 ...

Access this course and 1400+ top-rated courses and projects.