Question: 2 1 m left 3 . Question 3 A university has exactly one turnstile. It can be used either as an ALL exit or an

21m
left
3. Question 3
A university has exactly one turnstile. It can be used either as an
ALL
exit or an entrance. Unfortunately, sometimes many people want to pass through the turnstile and their directions can be different. The ith person comes to the turnstile at time[i] and wants to either exit the university if direction [i]=1 or enter the university if direction [i]=0. People form 2 queues, one to exit and one to enter. They are ordered by the time when they came to the turnstile and, if the times are equal, by their indices.
If some person wants to enter the university and another person wants to leave the university at the same moment, there are three cases:
If in the previous second the turnstile was not used (maybe it was used before, but not at the previous second), then the person who wants to leave goes first.
If in the previous second the turnstile was used as an exit, then the person who wants to leave goes first.
If in the previous second the turnstile was used as an entrance, then the person who wants to enter goes first.
Passing through the turnstile takes 1 second.
For each person, find the time when they will pass through the turnstile.
Function Description
Complete the function getTimes in the editor below.
getTimes has the following parameters:
int time[n]: an array of n integers where the value at index i is the time in seconds when the ith person will come to the turnstile int direction n : an array of n integers where the value at index i is the direction of the ith person
Returns:
int n : an array of n integers where the value at index i is the time when the ith person will pass the turnstile
Constraints
1n105
 21m left 3. Question 3 A university has exactly one turnstile.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!