WalzoneInterview Prep
πŸ“ž Interviewing soon? Practice with a realistic AI mock phone interview β€” it calls you, then scores you. First 15 min FREE β†’

Coding Interview Essentials Β· Stack and Queue Problems Β· question 56 of 120

How would you design a call center with three levels of employees: operator, supervisor, and director using queues?

πŸ“• Buy this interview preparation book: 120 Coding Interview Essentials questions & answers β€” PDF + EPUB for $5

The task can be accomplished using a priority queue where elements are sorted based on their importance in ascending or descending order.

The priority queue is a data structure that is very similar to a queue and it is used to manage data that has been assigned a priority. In a priority queue, items with higher priority get ahead of items with lower priority or based on the sequence data arrived. Priorities could be both i.e. in increasing and decreasing order.

## Levels Of Employees:

- Operator (Level - 1)

- Supervisor (Level - 2)

- Director (Level - 3)

In the scenario you described, the problem sounds like it might be best modeled by multiple queues, one for each role, rather than a single priority queue. We could pull calls off of the different queues based on the priority of the role. The operators would promise to offload as many calls as possible through a round-robin from their queue, followed by the supervisors, and then the directors if necessary.

### Operator

They will handle the calls first.


Q_op = {c_1, c_2, c_3, …, c_n}

Where Q_op denotes the queue of operators and c_i are the calls waiting in the queue.

### Supervisor

If all operators are busy, the call goes to Supervisor.


Q_sp = {c_nβ€…+β€…1, c_nβ€…+β€…2, c_nβ€…+β€…3, …, c_2n}

Where Q_sp denotes the queue of supervisors.

### Director

If all operators and supervisors are busy, the call goes to Director.


Q_dir = {c_2nβ€…+β€…1, c_2nβ€…+β€…2, c_2nβ€…+β€…3, …, c_3n}

Where Q_dir denotes the queue of directors.

### Algorithm

Here is a pseudo-code that describes the logic of the call-handling process:

while (incoming_calls): 
  if not queue_operators.is_empty():
    assign_call(queue_operators.dequeue())
  elif not queue_supervisors.is_empty():
    assign_call(queue_supervisors.dequeue())
  elif not queue_directors.is_empty():
    assign_call(queue_directors.dequeue())
  else:
    # Make the call wait in a queue
    wait_queue.enqueue(incoming_call)

Here, β€˜assign_call()β€˜ is a function to assign the call to the respective employee. And, β€˜enqueue()β€˜ and β€˜dequeue()β€˜ are basic queue operations to insert an element into the queue and remove an element from the queue respectively.

This way, every incoming call will be directly assigned to an operator unless all operators are busy. The call will be then escalated to the supervisor if all operators are currently busy. If supervisors are also busy, then it will be escalated to directors.

If all three levels are busy at the moment, the incoming calls will wait in a separate queue until they get a free slot from any of the three levels (i.e., Operator, Supervisor, and Director).

The model assumes calls are serviced one by one, and the hierarchy is strict, i.e., an available supervisor won’t pick a call if there is any operator free. This guarantees that calls are handled at the lower level possible.

This model can be enhanced by time slicing or allowing higher levels to pick calls if they have been idle for too long, but those details depend on the business rules of the call center.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Coding Interview Essentials interview β€” then scores it.
πŸ“ž Practice Coding Interview Essentials β€” free 15 min
πŸ“• Buy this interview preparation book: 120 Coding Interview Essentials questions & answers β€” PDF + EPUB for $5

All 120 Coding Interview Essentials questions Β· All topics