Phone Screen Round for L4
Anonymous User
2362

I have given my phone screen round for Google today so the question goes like this
there is some story written which is of no use
Now the main part we will be given a list of log messages from different sources and we have to truncate those log messages based two conditions

  1. If the number of log messages emiited from any source is more than X then we have to truncate them to X messages
  2. If the number of log messages emiited from any source is less than equal X then we have to truncate all of them

Now we have to find a maximum value of X such that after truncation the total truncated messages is max_size or fewer. And print the trucated list

Solution:

  1. Solve this using binary search to find the maximum value of X and then print the first X messages of every source
  2. Maximum value of X is 1 in this case
  3. size of list of log message = 1E5
  4. Solution Link: https://onlinegdb.com/8tmxh46Av

Ex:

Struct LogMessage{
   string source;
   string content
};

vector<LogMessage>logMessages = {
    {source_a, m},
    {source_a, m},
    {source_b, m}
};

max_size = 2;

After truncation -->  vector<LogMesaage> trucatedList = { {source_a, m}, {source_b, m} }
Comments (4)