Algorithm · Google · Hard
All n nodes of a rooted tree must be removed one at a time. A node can be removed only when all of its children have already been removed. In addition to the tree structure, there are m extra precedence rules: for each rule i, node before[i] must be removed before node after[i]. Return the lexicographically smallest valid removal order as an integer array of size n. If the tree restrictions plus the extra rules make it impossible to remove every node because they form a…
Checking your access…