I am glad that you passed the first stages of the interview process 🎉🥳. Now is the time to show us what you got!
There are two classes of messages in a particular network: ServerResponse and ClientRequest. Both inherit the Message class.
class Message {
public:
string messageId;
Message(){}
};
class ServerResponse : public Message{
public:
string serverId;
string metadata;
ServerResponse(string messageId, string serverId, string metadata){
this->messageId = messageId;
this->serverId = serverId;
this->metadata = metadata;
}
};
class ClientRequest : public Message{
public:
string clientId;
int requestTime;
ClientRequest(string messageId, string clientId, int requestTime){
this->messageId = messageId;
this->clientId = clientId;
this->requestTime = requestTime;
}
};Implement a customQueue that supports enqeue and deque operations for both types. Basically, it should support 4 operations.
- void enqeueue(ServerResponse e): Returns nothing and enqueues the element e at the end of the queue.
- void enqeueue(ClientRequest e): Returns nothing and enqueues the element e at the end of the queue.
- void deque(): Returns nothing and deletes the front element of the queue.
- string getFront(): Returns the front element of the queue as a string.
- If the front element is a ServerResponse then the output string should be formatted as <messageId> <serverId> <metadata>.
- If the front element is a ClientRequest then the output string should be formatted as <messageId> <clientId> <requestTime>. Note that different words in getFront() are separated by a single space. It is guaranteed that all the queries are valid.
- unsigned int getCountClients(): Returns the number of distinct clientIds present on queue.
- unsigned int getCountServers(): Returns the number of distinct serversIds present on queue.
We highly recommend showcasing the following in your solution:
- Memory allocation (constructors & destructors)
- Pointers
- Arrays/Vectors (STL library)
- STL Algorithms
- Type conversion
Example Consider the following 5 queries
- Enqueue a ClientRequest with messageId = "m1", clientId = "C1" and requestTime = 10
- Enqueue a ServerRequest with messageId = "m2", serverId = "S1" and metadata = "4bytes,1second"
- Enqueue a ClientRequest with messageId = "m3", clientId = "C2" and requestTime = 15
- Get count of clients
- Get count of servers.
- Get the front element.
- Pop.
- Get the front element.
The output should look like:
2 // Count of distinct current clients
1 // Count of distinct current servers
"m1 C1 10" // front of queue
"m2 S1 4bytes,1second" // front of queueConstraints
- 2 ≤ number of queries ≤ 1000
- 3 ≤ length of each query string ≤ 100
- 1 ≤ |messageId| ≤ 50
- 1 ≤ |clientId| ≤ 50
- 1 ≤ |serverId| ≤ 50
- 1 ≤ |metadata| ≤ 50
- 1 ≤ requestTime ≤ 1000
- It is guaranteed that there is at least one "Top" query.
- You should submit your code in a GitHub fork repository
- Commit as much as you want, remember to show good practices.
- Try to code as clean as possible. Think of it as if you were tasked in real life.
Good Luck!
