AmazonOA #188
Find Requests in Queue
Estimated MediumJudge-ready
Topics (AI-labelled)SimulationHashing
At time 0 all requests join the queue. Each second the front request is processed; it still counts toward that second's size and is removed the following second. Every other request expires and is removed immediately at t=wait[i], and it can only start being served while t<wait[i]. Output the queue length at every second from time 0 until the queue is empty, including the final 0.
Input
The first line contains n; the second line contains n waiting deadlines. 1≤n≤100000, 1≤wait[i]≤100000.
Output
Output the queue length at each time, separated by spaces; the last value is 0.
Example 1
Input:
4
2 2 3 1
Output:
4 2 1 0
Example 2
Input:
3
4 4 4
Output:
3 2 1 0
Example 3
Input:
4
3 1 2 1
Output:
4 1 0
Example notes
The three examples give 4 2 1 0, 3 2 1 0 and 4 1 0.
Editorial
Loading solution…