You receive a stream of test-run events, each carrying a test_id, a timestamp, and a status. Timestamps are strictly increasing across all test IDs. Implement a log(...) method to record each event, and get(...) methods to answer the queries below.
get(test_id) returns a number or null: the shortest duration for that test to transition from a failing status to a passing status. If the test logs several failures in a row, treat the first failure of that consecutive block as the start of the interval.log(...). Add a query get(min_tests) that returns the longest continuous time window during which at least min_tests distinct tests are simultaneously failing. Which specific tests are failing doesn’t matter, only that the count stays at or above the threshold for the whole window.start_timestamp (inclusive) and end_timestamp (exclusive) of that failure window.log("A", 1, "fail")
log("A", 3, "fail")
log("A", 5, "pass")
get("A") // returns 4 (first failure at 1 → pass at 5)
log("B", 2, "fail")
log("B", 4, "pass")
get("B") // returns 2
get("C") // returns null (no data)
log("A", 1, "fail")
log("B", 2, "fail")
log("A", 4, "pass")
log("C", 5, "fail")
log("B", 7, "pass")
log("C", 9, "pass")
get(2) // returns { start_timestamp: 2, end_timestamp: 4 }
// (A and B are both failing from 2 up to, but not including, 4)