Back to problems

Delete a Subtree by Marking Nodes as Removed

Algorithm · Pinterest · Medium

Remove a Node and All Descendants in a Forest Medium · Topics · Company Tags · Hints A forest is given as an array parent of length n. For each index i (0‑based), parent[i] is the index of the parent of node i, or parent[i] == i when i is the root of a tree. The array is guaranteed to represent a forest – a collection of one or more trees with no cycles. You are given an integer target (0 <= target < n). Delete the node target and every node that is a descendant of target in…

Checking your access…