Log Buffer Analyzer
You receive n logs in increasing timestamp order. Log j has:
logTimestamp[j](milliseconds)logTag[j](a string)
The system keeps logs in a circular buffer of size bufferCapacity. When a new log arrives:
- Add the new log to the buffer.
Transmit every log currently in the buffer that:
- has the same tag as the new log, and
- has timestamp
tsuch thatnewTimestamp - t <= transmissionWindow
If adding the new log makes the buffer exceed bufferCapacity, remove the oldest log.
Return the total number of transmitted logs over all arrivals, counting logs each time they are transmitted.
The function getTotalTransmittedLogs takes the following parameters:
int logTimestamp[n]: the recording times of logs in millisecondsstring logTag[n]: the tags of logsint bufferCapacity: the capacity of the circular bufferint transmissionWindow: the time range (in milliseconds) within which logs sharing the same tag as the arriving log are transmitted
The function should return the number of logs transmitted during the process as an integer.
logTimestamp = [1000, 2000, 3000, 4000] logTag = ["error", "warning", "error", "warning"] bufferCapacity = 3 transmissionWindow = 2000 return = 6
Processing the log arrivals:
- At timestamp
1000, the buffer contains the newerrorlog, so1log is transmitted. - At timestamp
2000, the buffer contains the newwarninglog, so1log is transmitted. - At timestamp
3000, botherrorlogs at1000and3000are within the window, so2logs are transmitted. - At timestamp
4000, bothwarninglogs at2000and4000are within the window, so2logs are transmitted.
The total number of transmitted logs is 1 + 1 + 2 + 2 = 6.
Source correction (June 28, 2026): I found a newer source image that showed this example and function name differently, so I updated this version to match it. If you have the full prompt or see something off, please tell us and we'll fix it. If a clearer source shows up later, I'll update this again. 🐿️
Source note (June 28, 2026): The original post did not include the output for this example. FastPrep worked it out from the problem statement and the given input. If you have the original output or notice something wrong, please let us know and we'll fix it. If we find the original source later, we'll come back and update this too. 🦦
public int getTotalTransmittedLogs(int[] logTimestamp, String[] logTag, int bufferCapacity, int transmissionWindow) {
// write your code here
}