Implement test failure analytics APIs
Company: Vanta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates a candidate's ability to design efficient data structures and algorithms for time-series event logging, interval computation, and tracking concurrent failure states across distinct identifiers.
Part 1: Minimum Fix Time per Test
Constraints
- 0 <= n <= 2 * 10^5
- 0 <= len(queries) <= 2 * 10^5
- len(test_ids) == len(timestamps) == len(statuses)
- timestamps are strictly increasing
- Each status is either 'pass' or 'fail'
Examples
Input: (['A', 'A', 'A', 'A', 'A'], [1, 2, 5, 8, 10], ['fail', 'fail', 'pass', 'fail', 'pass'], ['A'])
Expected Output: [2]
Explanation: Test A has two completed failure blocks: [1 -> 5] with duration 4, and [8 -> 10] with duration 2. The minimum is 2.
Input: (['A', 'B', 'A', 'B', 'A', 'A'], [1, 2, 4, 7, 8, 9], ['fail', 'fail', 'pass', 'pass', 'fail', 'pass'], ['A', 'B', 'C'])
Expected Output: [1, 5, -1]
Explanation: A has fix times 3 and 1, so answer is 1. B has one fix time 5. C never appears, so answer is -1.
Hints
- Track, for each test, whether it is currently in a failure block and when that block started.
- When a 'pass' arrives for a test that is currently failing, compute one candidate duration and update that test's minimum.
Part 2: Longest Interval with At Least K Concurrent Failures
Constraints
- 0 <= n <= 2 * 10^5
- 0 <= len(min_tests_queries) <= 2 * 10^5
- len(test_ids) == len(timestamps) == len(statuses)
- timestamps are strictly increasing
- Each status is either 'pass' or 'fail'
- 1 <= min_tests_queries[i] <= 2 * 10^5
Examples
Input: (['A', 'B', 'C', 'A', 'B', 'C'], [1, 2, 4, 5, 7, 8], ['fail', 'fail', 'fail', 'pass', 'pass', 'pass'], [1, 2, 3, 4])
Expected Output: [[1, 8], [2, 7], [4, 5], [-1, -1]]
Explanation: The failure counts on segments are: [1,2):1, [2,4):2, [4,5):3, [5,7):2, [7,8):1. So the best intervals are [1,8) for k=1, [2,7) for k=2, [4,5) for k=3, and none for k=4.
Input: (['A', 'A', 'B', 'B'], [1, 3, 5, 7], ['fail', 'pass', 'fail', 'pass'], [1, 2])
Expected Output: [[1, 3], [-1, -1]]
Explanation: There are two length-2 intervals with at least 1 failing test: [1,3) and [5,7). The tie is broken by earliest start, so [1,3) is returned.
Hints
- First convert the logs into consecutive time segments where the number of currently failing tests is constant.
- Then think of each query k as asking for the longest contiguous run of adjacent segments whose failure count is at least k. You can answer all k values efficiently by processing thresholds from high to low.