1675. VIP Lane Service

Easy1.5 points estimatedQueueSimulationArray

A service desk has a regular line and a VIP line. The array ops describes events in order. A positive value ops[i] means a regular customer with that id joins the back of the regular line. A negative value means a VIP customer with id -ops[i] joins the back of the VIP line. A zero means the clerk serves one customer: the front of the VIP line if it is not empty, otherwise the front of the regular line.

Return the ids of the served customers in the order they were served, with -1 recorded for a serve event that finds both lines empty. The result has one entry per zero in ops and is empty when ops has no zeros. Use two queues; the work is O(n) time and O(n) space with 1 <= n = ops.length <= 1000 and -10^4 <= ops[i] <= 10^4. Ids are not required to be distinct.

Example 1

Input:
ops = [5,-7,0,0,0]
Output:
[7,5,-1]
Explanation:

VIP 7 is served first, then regular 5, and the last serve finds both lines empty.

Example 2

Input:
ops = [3,0,-2,4,0,0]
Output:
[3,2,4]
Explanation:

3 is served alone, then VIP 2 jumps ahead of regular 4.

Example 3

Input:
ops = [0,0]
Output:
[-1,-1]
Explanation:

Nobody is waiting, so both serves report -1.

Constraints

1 ≤ ops.length ≤ 1000; -104 ≤ ops[i] ≤ 104

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(n)
Space
O(n)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…