Skip to content
Discussion options

You must be logged in to vote

We are going to design a Router class with the following:

Approach:

  1. Initialization: The Router class is initialized with a memory limit, a queue to manage packets in FIFO order, a set to check for duplicates, and a dictionary to store timestamps of packets grouped by destination.
  2. Adding Packets: When adding a packet, check for duplicates using a composite key of source, destination, and timestamp. If the memory is full, remove the oldest packet from the queue and update the dictionary. Add the new packet to the queue, set, and dictionary.
  3. Forwarding Packets: Remove the oldest packet from the queue and return it. Update the set and dictionary accordingly.
  4. Counting Packets: For a given des…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Sep 20, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Sep 20, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants