I'm reading the book Cracking the Code.
The answer for this question suggests a solution using timestamps and two separate queues. This is straightforward and involves simply enqueuing into the appropriate queues. Dequeuing oldest involves checking timestamps of front of both queues and removing the oldest.
I'm wondering if there is a way to do this without using an additional timestamp field.
My approach is to use two queues,
I simply push into
Dequeue Dog/Cat aka. specific type dequeue
I check if front of
main has this type. If not or if
main is empty, then I go to
backup contains the right type,
backup does not contain it, then shift from
Dequeue oldest pet
main has elements
main is empty,