Delete a Subtree by Marking Nodes as Removed

You are given a forest represented by an array forest. An array index is the node value, and forest[i] stores the parent_idx of node i.

  • If parent_idx == i, node i is the root of a tree....

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: