Company: Linkedin
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. (In other words, a valid log table is any breadth-first traversal of the process tree starting at Process 1; children of the same parent may be enqueued in any order.) Inputs There are n processes, numbered from 1 to n . Parent-child relationships between processes are given by two arrays, process_from[i] and process_to[i] , where process_from[i] is a parent of process_to[i] (