Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Delete Nodes And Return Forest

XPChallenge Points: 20
levelLevel: Medium

You’re given a binary tree root (distinct node values) and an array to_delete.
Delete every node whose value is in to_delete. When a node is deleted, any non-null children become new roots (unless they’re also deleted).
Return the list of roots of the resulting forest, in any order.

Example 1:

Input: root = [1,2,3,4,5,6,7], to_delete = [3,5]

Output: [[1,2,null,4],[6],[7]]

Example 2:

Input: root = [1,2,4,null,3], to_delete = [3]

Output: [[1,2,4]]

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result