Build an in-memory service to log test run results and answer two queries. Assumptions: events arrive with strictly increasing timestamps across all test IDs. Implement:
-
log(test_id, timestamp, status): Record a status update where status ∈ {'pass','fail'}.
-
getMinPassTransition(test_id): Return the minimum elapsed time for this test to change from failing to passing. Treat consecutive 'fail' reports as one failure segment that begins at the first 'fail' in that run. If a failure segment never transitions to 'pass', ignore it. Return the duration as a number in the timestamp units, or null if no complete fail→pass transition exists.
Follow-up: Keep the same logging function and add:
-
getMaxConcurrentFailures(min_tests): Find the longest contiguous time interval during which at least min_tests distinct tests are failing simultaneously. Return an object { start_timestamp:
<inclusive>
, end_timestamp:
<exclusive>
}. If no such interval exists, return null. Clarify tie-breaking (e.g., return the earliest longest interval). Describe data structures, update/query algorithms, and analyze time and space complexity under streaming inserts.