Delete a Forest Subtree and Compact Parent Indices

You are given a forest with n nodes labeled from 0 to n - 1. In the array parent:

  • parent[i] = -1 means node i is a root.
  • Otherwise, parent[i] is the index of node i's parent.

The...

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: