Log Server Window Counts
EasyLog Parsing · Optiver
A log server stores entries [timestamp, severity, message], where timestamp is an integer and severity is a string such as "ERROR". The logs are not necessarily in timestamp order.
Each query is [start, end, severity] with start <= end. Its answer is the number of log entries whose severity equals severity exactly (case-sensitive) and whose timestamp satisfies start <= timestamp <= end.
Return one row [severity, count] per query, in the same order as queries. A severity that never appears simply has count 0.
There can be many logs and many queries, so avoid scanning every log for every query.
Example 1
- Input:
- logs = [[17, "ERROR", "disk full"], [4, "INFO", "boot"], [9, "ERROR", "timeout"], [12, "WARN", "slow"], [9, "ERROR", "retry"]], queries = [[5, 15, "ERROR"], [0, 20, "WARN"], [10, 16, "ERROR"]]
- Output:
- [["ERROR", 2], ["WARN", 1], ["ERROR", 0]]
- Explanation
- Between 5 and 15 the
ERRORentries are the two at timestamp 9 (the one at 17 is outside). The onlyWARNentry is at 12. NoERRORfalls in[10, 16].
Example 2
- Input:
- logs = [[3, "INFO", "a"], [8, "INFO", "b"]], queries = [[3, 8, "INFO"], [4, 7, "INFO"]]
- Output:
- [["INFO", 2], ["INFO", 0]]
- Explanation
- Both endpoints are inclusive, so
[3, 8]catches both entries, while[4, 7]catches neither.
Example 3
- Input:
- logs = [[1, "error", "x"]], queries = [[0, 5, "ERROR"]]
- Output:
- [["ERROR", 0]]
- Explanation
"error"and"ERROR"are different severities, so the count is0.
Constraints
- 0 ≤ logs.length, queries.length ≤ 105
- 0 ≤ timestamp, start, end ≤ 109
start <= endfor every query.- Severity strings are compared exactly.