FastPrepFastPrep
Problem Brief

Log Buffer Analyzer

OA

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:

    1. int logTimestamp[]: the recording times of logs in milliseconds
    2. string logTag[]: the tags of logs
    3. int bufferCapacity: the capacity of the circular buffer
    4. int 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!

    1Example 1

    Input
    logTimestamp = [1000, 2000, 3000, 4001], logTag = ["error", "warning", "error", "warning"], bufferCapacity = 3, transmissionWindow = 2000
    Output
    5
    Explanation
    Example 1 illustration

    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.

    public int getNumberTransmittedLogs(int[] logTimestamp, String[] logTag, int bufferCapacity, int transmissionWindow) {
      // write your code here
    }
    
    Input

    logTimestamp

    [1000, 2000, 3000, 4001]

    logTag

    ["error", "warning", "error", "warning"]

    bufferCapacity

    3

    transmissionWindow

    2000

    Output

    5

    Sign in to submit your solution.