Goldman SachsOA #20
Log Buffer Analyzer
估计中等评测数据准备中,可先阅读题面
考点(AI 标注)模拟/实现哈希计数
You are given a logging system with a circular buffer that can hold up to n logs. Each log has a unique timestamp logTimestamp[i] (in milliseconds) and a tag logTag[i]. When a new log arrives, the system:
renames all logs sharing the same tag as the new log, but only if they fall within a specific time window (transmissionWindow).
If the buffer is full, it removes the oldest log to make space for the new one.
Implement a function that finds the total number of logs transmitted throughout the process as logs arrive, considering the circular buffer's capacity and the time window for transmission.
Function Description
Complete the function getNumberTransmittedLogs in the editor
getNumberTransmittedLogs takes the following parameters:
int logTimestamp[]: the recording times of logs in millisecondsstring logTag[]: 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 Returns int: the number of logs transmitted during the process A SUPER huge thank you to our incredible friend for everything they've contributed!
Example 1
Input:
logTimestamp = [1000, 2000, 3000, 4001]
logTag = ["error", "warning", "error", "warning"]
bufferCapacity = 3
transmissionWindow = 2000
Output:
5
Explanation: The logs received are as follows:
- Log 1: Timestamp = 1000 ms, Tag = "error"
- Log 2: Timestamp = 2000 ms, Tag = "warning"
- Log 3: Timestamp = 3000 ms, Tag = "error"
- Log 4: Timestamp = 4001 ms, Tag = "warning" Condition of Buffer and logs transmitted during the process: The total number of logs transmitted during the process is 5, thus, the function should return 5.