Company: HackerRank
Difficulty: medium
An antivirus software uses a log of open processes to detect viruses by analyzing the hierarchical order of processes. Each process may have child processes, which must appear in the log table after the parent process, as child processes are only initiated by their parent. There is no cyclic relationship, and Process 1 is the designated bootstrap process (the first process to run). Process Log Generation Enqueue Process 1 in a queue (FIFO). While the queue is not empty: Add the first entry in the queue to the log table. Add any child processes of this entry to the queue. Remove the initial process from the queue. The children of a process may be added to the queue in any order, so a single process hierarchy can generate many different valid log tables. Task There are n processes, numbered from 1 to n , and the parent-child relationships form a tree. You are given q queries, each an order of the log table. Due to potential malware, an order may not follow the original hierarchical struc