Skip to content

HTS-Mexico/Cpp-assessment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Honeywell Logo

Hello #FutureShaper

I am glad that you passed the first stages of the interview process 🎉🥳. Now is the time to show us what you got!

Problem description:

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

  1. Enqueue a ClientRequest with messageId = "m1", clientId = "C1" and requestTime = 10
  2. Enqueue a ServerRequest with messageId = "m2", serverId = "S1" and metadata = "4bytes,1second"
  3. Enqueue a ClientRequest with messageId = "m3", clientId = "C2" and requestTime = 15
  4. Get count of clients
  5. Get count of servers.
  6. Get the front element.
  7. Pop.
  8. 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 queue

Constraints

  • 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.

Submission

  • 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!

About

C++ assessment

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published