In a management Role interview with Facebook engineer asked me this in design interview, He was very aggressive and laughing at my questions and getting intimidated with similar questions you guys had here. My solution for this would be linked list of linked list, one sorted based on priority, the second one sorted based on timestamp, This means the first linked list will always have the highest priority queue in the first node(s), and that node(s) will always have the packet(s) with earliest timestamp, now, one api needs to search to find the earliest packet based on time stamp for a priority: find_earliest_packet(priority_t), which basically will look for the first packets timestamp in first node of queues linked list for that particular priority. struct packet { data; t_stamp; struct packet *next; }; struct queue { struct packet *packet; int priority; struct queue *next }; both of these should be sorted, packet linked list based on time_stamp, queue linked list based on priority, some support linked list functions like pop and insert will be required for high level find_earliest_packet(priority_t) function construction, firstthis function needs to read the first node in queue linked list, get the time stamp of the first packet in its own linked list, check to see if the nest node in the queue has the same priority or not, if yes compare time stamps, and consturct array of packets with same priorities based on their time stamp and send it to HW, this could go until we reach to the end of queue linklist. Inserting position of new packet_list (sorted list of data packets based on time_stamp) to the queue linked list only needs to be based on priority of the queue from the app. The guy was so rude which I gave up on him, It was so clear he has been beaten up so much. The intention of design question is to see the person tough process, Specially for people Management role, rather than looking for a pure complicated linked list integration to fix a bad design from the get go. Great videos by the way!
In a management Role interview with Facebook engineer asked me this in design interview, He was very aggressive and laughing at my questions and getting intimidated with similar questions you guys had here. My solution for this would be linked list of linked list, one sorted based on priority, the second one sorted based on timestamp, This means the first linked list will always have the highest priority queue in the first node(s), and that node(s) will always have the packet(s) with earliest timestamp, now, one api needs to search to find the earliest packet based on time stamp for a priority: find_earliest_packet(priority_t), which basically will look for the first packets timestamp in first node of queues linked list for that particular priority.
struct packet
{
data;
t_stamp;
struct packet *next;
};
struct queue {
struct packet *packet;
int priority;
struct queue *next
};
both of these should be sorted, packet linked list based on time_stamp, queue linked list based on priority, some support linked list functions like pop and insert will be required for high level find_earliest_packet(priority_t) function construction, firstthis function needs to read the first node in queue linked list, get the time stamp of the first packet in its own linked list, check to see if the nest node in the queue has the same priority or not, if yes compare time stamps, and consturct array of packets with same priorities based on their time stamp and send it to HW, this could go until we reach to the end of queue linklist. Inserting position of new packet_list (sorted list of data packets based on time_stamp) to the queue linked list only needs to be based on priority of the queue from the app.
The guy was so rude which I gave up on him, It was so clear he has been beaten up so much. The intention of design question is to see the person tough process, Specially for people Management role, rather than looking for a pure complicated linked list integration to fix a bad design from the get go.
Great videos by the way!