- Lastly, the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.
the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.
Lastly, I wonder if we can use priority queues instead of plain old queues here?
- Lastly, the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.
the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.
Lastly, I wonder if we can use priority queues instead of plain old queues here?
I got this question during an interview. The question itself was very open-ended - it asked me to implement a ticket queue system, where by default it would have 3 different queues to holderhold tickets that are of severity 1, severity 2, and severity 3 respectively. It should have functionalities like 1. add a ticket to the corresponding queue 2. get the ticket from the highest severity (priority) queue 3. resolve ticket i.e. remove the ticket from the queue 4. loop over the tickets starting at the highest severity to the lowest severity 5. check if a ticket is in the queue.:
- add a ticket to the corresponding queue
- get the ticket from the highest severity (priority) queue
- resolve ticket i.e. remove the ticket from the queue
- loop over the tickets starting at the highest severity to the lowest severity
- check if a ticket is in the queue.
Finally, the design should be easily extensible to adapt future changes e.g. adding a new queue.
It doesn't have any predefined data structure for either the queue or the ticket so we have to come up with our own design. Here is how I implemented:
First for the tickets I have a class Ticket
:
And for the ticket queues I have this:
I got this question during an interview. The question itself was very open-ended - it asked me to implement a ticket queue system, where by default it would have 3 different queues to holder tickets that are of severity 1, severity 2, and severity 3 respectively. It should have functionalities like 1. add a ticket to the corresponding queue 2. get the ticket from the highest severity (priority) queue 3. resolve ticket i.e. remove the ticket from the queue 4. loop over the tickets starting at the highest severity to the lowest severity 5. check if a ticket is in the queue. Finally, the design should be easily extensible to adapt future changes e.g. adding a new queue
It doesn't have any predefined data structure for either the queue or the ticket so we have to come up with our own design. Here is how I implemented
First for the tickets I have a class Ticket
And for the ticket queues I have this
I got this question during an interview. The question itself was very open-ended - it asked me to implement a ticket queue system, where by default it would have 3 different queues to hold tickets that are of severity 1, severity 2, and severity 3 respectively. It should have functionalities like:
- add a ticket to the corresponding queue
- get the ticket from the highest severity (priority) queue
- resolve ticket i.e. remove the ticket from the queue
- loop over the tickets starting at the highest severity to the lowest severity
- check if a ticket is in the queue.
Finally, the design should be easily extensible to adapt future changes e.g. adding a new queue.
It doesn't have any predefined data structure for either the queue or the ticket so we have to come up with our own design. Here is how I implemented:
First for the tickets I have a class Ticket
:
And for the ticket queues I have this:
- Lastly, the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.
- Lastly, the current implementation is inherently susceptible to starvation. e.g. as long as the sev1 queue is not empty, we will always start with tickets in sev1 queue when looping over the system even when there might a sev2 ticket that has been there for a long long time.