Company: HackerRank_26thjune
Difficulty: medium
An antivirus tool detects malware by checking the order in which processes appear in a log table. There are processNodes processes, numbered 1 to processNodes . Every process except process 1 is started by exactly one parent process, and a child process can only be started by its parent, so a child always appears in the log after its parent. There are no cycles, and process 1 is the bootstrap process: the first process to run. The log table is generated like this: Put process 1 into a FIFO queue. While the queue is not empty: append the process at the front of the queue to the log table; add every child process of that entry to the back of the queue, in any order; remove that entry from the queue. Because the children of a process may be added to the queue in any order, one process hierarchy can produce many different log tables. The hierarchy is given as processNodes - 1 pairs processFrom[i] , processTo[i] : one of the two processes is the parent of the other (either processFrom[i] is