1173. Error Window Count

Easy1.5 points estimatedStringCounting

A support engineer is scanning a server log for trouble during a short outage. Each element of logs is a line of the form "HH:MM:SS LEVEL message", where LEVEL is one uppercase word and the message is one or more words separated by single spaces.

Convert each line's time to seconds since midnight and return how many lines have a level of exactly "ERROR" and a time inside the window from startTime to endTime, both given as "HH:MM:SS" and both inclusive. A word ERROR inside the message does not make a line an error line, and a level such as ERRORS does not match.

A single pass over the lines runs in linear time in the total text length.

Example 1

Input:
logs = ["09:00:01 ERROR disk full","09:30:00 INFO all good","10:00:00 ERROR retry failed"]startTime = "09:00:00"endTime = "09:59:59"
Output:
1
Explanation:

Only the first line is an ERROR inside the window; the third is at 10:00:00, after the end.

Example 2

Input:
logs = ["12:00:00 ERROR timeout","12:00:00 WARN ERROR in message"]startTime = "12:00:00"endTime = "12:00:00"
Output:
1
Explanation:

Both ends are inclusive; the second line has level WARN, so its message does not count.

Constraints

1 ≤ logs.length ≤ 1000

All times lie within one day and startTime ≤ endTime

The message may contain spaces

How this problem is judged

Answers
Your answer must match exactly. Numbers compare by value, so 2 and 2.0 are equal.

Expected complexity

Time
O(total length)
Space
O(1)

What the author was aiming for. Your own solution is not measured against it.

Asked in an interview

Were you asked this in an interview? Say where, anonymously.

Code
Loading the editor…