A server log is a list of lines. A line is an error line when it starts with "ERROR". Error lines that are close together usually describe the same problem, so they are grouped into incidents: an error line joins the current incident when at most gap non-error lines separate it from the previous error line; otherwise it starts a new incident.
Write incidents(log, gap) that returns one pair (first, last) per incident, the line numbers of its first and last error line. Line numbers start at 1. Incidents are listed in order.
Examples
Input: log = ["boot", "ERROR disk", "ERROR disk", "ok", "ok", "ERROR net", "ok"], gap = 1
Output: [(2, 3), (6, 6)]
Explanation: Lines 2 and 3 are adjacent. Two ok lines separate line 3 from line 6, more than gap = 1.
Input: same log, gap = 2
Output: [(2, 6)]
Input: log = ["ok", "WARNING ERROR?"], gap = 0
Output: []
Explanation: The second line does not start with "ERROR".
Constraints
0 <= len(log) <= 10**5,0 <= gap <= 10**5
Goals
- Loop over items and their 1-based positions with `enumerate(..., start=1)`
- Extend the last group or start a new one by comparing positions
- Keep the loop free of manual index bookkeeping