Phone Screen Round for L4

google logo
google
SDE II
April 3, 20253 reads

Summary

I had a phone screen round for Google L4, where I was asked a challenging log message truncation problem which I approached using binary search to find the optimal 'X'.

Full Experience

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} }

Interview Questions (1)

Q1
Log Message Truncation with Max Size
Data Structures & Algorithms

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 emitted from any source is more than X then we have to truncate them to X messages.
  2. If the number of log messages emitted from any source is less than or equal to 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 truncated list.

Example:

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} }
Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!