Computers and Technology
Computers and Technology, 21.03.2020 07:11, aks3489

A university has exactly one turnstile. It can be used either as an 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 direciton[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

The function must return an array of n integers where the value at index[i] is the same when the ith person will pass the turnstile

The function has the following params:

• time: an array of n integers where the value at index i is the time when the
ith person will came to the turnstile
• direction: an array of n integers where the value at index i is the direction
of the ith person

Constraints

• 1 <= n <= 105
• 0 <= time[i] <= 109 for 0 <= i <= n – 1
• time[i] <= time[i+1] for 0 <= i <= n - 2
• 0 <= direction [i] <= 1 for 0 <= i <= n – 1

Example:

n = 4

time = [0,0,1,5]

direction = [0,1,1,0]

Output = [2,0,1,5]

Example 2

n = 5

time = [0,1,1,3,3]

direction = [0,1,0,0,1]

Output = [0,2,1,4,3]

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 09:00, starwarsfan1975
Meenu wants to create a high quality drawing in a variety of colours. which device should she use for the same?
Answers: 1
image
Computers and Technology, 23.06.2019 01:50, rhonda45801
Free points just awnser this. what should i watch on netflix
Answers: 2
image
Computers and Technology, 23.06.2019 08:00, seaotter7140
Michael has written an e-mail to his employees that describes a new product special that will be introduced to the customers next week. by taking time to make sure the e-mail is well written, logical, and organized, michael has made sure his message has the characteristics of a) effective communicationb) ineffective communicationc) barriers to communicationd) workplace communication
Answers: 2
image
Computers and Technology, 23.06.2019 18:30, aalyssag606
This program should be a short piece of code that prints all of the positive integers from 1 to 100 as described more fully below. the program may contain multiple methods, and if using an oo language, should be contained within a single class or object. the program should be designed so that it begins execution when invoked through whichever mechanism is most common for the implementation language. â–ş print out all positive integers from 1 to 100, inclusive and in order. â–ş print messages to standard output, matching the sample output below. â–ş in the output, state whether the each integer is 'odd' or 'even' in the output. â–ş if the number is divisible by three, instead of stating that the number is odd or even, state that the number is 'divisible by three'. â–ş if the number is divisible by both two and three, instead of saying that the number is odd, even or divisible by three; state that the number is 'divisible by two and three'. â–ş design the logic of the loop to be as efficient as possible, using the minimal number of operations to perform the required logic. sample output the number '1' is odd. the number '2' is even. the number '3' is divisible by three. the number '6' is divisible by two and three.
Answers: 1
Do you know the correct answer?
A university has exactly one turnstile. It can be used either as an exit or an entrance. Unfortunate...

Questions in other subjects: