Question: Sometimes the canteen can get a bit crowded, especially the drinks stall. When that happens, at times we may look in the front of the
Sometimes the canteen can get a bit crowded, especially the drinks stall.
When that happens, at times we may look in the front of the queue to see if we see someone we know of in front. Then we will accidentally bump into our friend and ask him if he is ok to order for us or not. This especially happens when we are queueing up for Lim Chee Wan Ba Khwa or Hello Kitty stuff toys.
Your task is now to implement such a team queue.
The input is as follows:
if a person enters by the main queue, it will read
MainQueue Andrew
if a person enters by team queue, it will read
Andrew John
Hence if we have the following
Case 1:
MainQueue Andrew
MainQueue Alex
MainQueue Amy
Alex John
The output is this final state of the queue. This is the string that needs to be returned:
Andrew, Alex, John, Amy
Case 2:
MainQueue Andrew
MainQueue Alex
MainQueue Amy
Alex John
Alex Peter
The output is this final state of the queue. This is the string that needs to be returned:
Andew, Alex, John, Peter, Amy
Now we have no limitations. Anybody can jump into the queue in anybody.
Case 3:
MainQueue Andrew
MainQueue Alex
MainQueue Amy
Alex John
Alex Peter
John Jamie
Jamie Jack
John Adam
The output is this final state of the queue. This is the string that needs to be returned:
Andew, Alex, John, Jamie, Jack, Adam, Peter, Amy
Your code needs to be optimized. The maximum number of people in the queue is 10,000.
Assume also that all the names are unique and all commands are valid commands. Meaning that you will never be asked to team queue a person who is not in the actual queue.
Hint: The solution can be just a single dictionary
Input Format
5 MainQueue Andrew MainQueue Alex MainQueue Amy Alex John Alex Peter
Constraints
Assume also that all the names are unique and all commands are valid commands. Meaning that you will never be asked to team queue a person who is not in the actual queue. The maximum number of people in the queue is 10,000.
Output Format
Andrew Alex John Peter Amy
IN PYTHON.
Sample Input 0 3 MainQueue Alex MainQueue John MainQueue Amy Sample Output 0 Alex John Amy Sample Input 1 MainQueue Alex MainQueue John MainQueue Pe John Amy John Andrew Sample Output 1 Alex John Amy Andrew Peter
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
