Back to problems

Tree-Encoded Subtree Deletion and Stable Compaction

Algorithm · Pinterest · Hard

Delete Subtree and Compact Forest Array Medium · Topics · Company Tags · Hints You are given an integer array parent of length $$n$$ that represents a forest of rooted trees. Each index $$i$$ ($$0 \le i < n$$) corresponds to a node whose value is its original index. If the node is a root, then parent[i] == i; otherwise parent[i] is the index of its parent. You are also given a non‑negative integer target that denotes the index of a node. Perform the following two‑step…

Checking your access…