Log Stream Query Matching
MediumHash Map ยท Datadog
Given a list entries, each starting with Q: (register a query) or L: (a log line) followed by text, return one string per entry.
A word is a maximal run of ASCII letters and digits, compared ignoring case; every other character separates words. Queries get ids 1, 2, 3, ... in the order they appear.
- A query entry gives
registered <id>. - A log entry gives
matched <ids>: the ids, in increasing order and comma-separated, of queries registered earlier in the stream whose words all appear in the log, ormatched noneif there are none.
Example 1
- Input:
- entries = ["Q: disk full", "Q: error", "L: ERROR: disk is full on host-7", "L: disk usage ok"]
- Output:
- ["registered 1", "registered 2", "matched 1,2", "matched none"]
- Explanation
- The third entry contains disk, full and error, so both queries match. The last log has disk but not full.
Example 2
- Input:
- entries = ["L: boot ok", "Q: fail", "L: failed twice", "L: Fail, fail!"]
- Output:
- ["matched none", "registered 1", "matched none", "matched 1"]
Example 3
- Input:
- entries = ["Q: a b", "Q: b a a", "L:", "L: b,a"]
- Output:
- ["registered 1", "registered 2", "matched none", "matched 1,2"]
Constraints
0 <= entries.length <= 3000- Every entry starts with
Q:orL:, contains only printable ASCII characters and is at most 200 characters long - Every query contains at least one word