Phone Screen Round for L4
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
- If the number of log messages emiited from any source is more than X then we have to truncate them to X messages
- 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:
- Solve this using binary search to find the maximum value of X and then print the first X messages of every source
- Maximum value of X is 1 in this case
- size of list of log message = 1E5
- 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)
We will be given a list of log messages from different sources and we have to truncate those log messages based two conditions:
- If the number of log messages emitted from any source is more than X then we have to truncate them to X messages.
- 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} }