Delete a Subtree and Compact a Forest
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, nodeiis 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:
