PracHub
QuestionsLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Vanta
  • Coding & Algorithms
  • Software Engineer

Implement test failure analytics APIs

Company: Vanta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

##### Question Design a data structure that supports: log(testId, timestamp, status) — record the status ('pass'/'fail') of a test run; timestamps are strictly increasing across all test IDs. getMinFixTime(testId) — for the given testId, return the shortest duration from the first failure in any contiguous failure block to the next passing status; return null if the test never moves from failing to passing. ​ Follow-up: Extend the same logging function and implement getMaxConcurrentFailures(min_tests) — return the longest contiguous time interval [start, end) during which at least min_tests distinct tests are simultaneously failing (specific test IDs don't matter). Return an object {start_timestamp, end_timestamp} with end exclusive.

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

You are given a history of test-run logs in strictly increasing timestamp order. Each log entry is (test_id, timestamp, status), where status is either 'pass' or 'fail'. For one test, a contiguous failure block starts at the first 'fail' after the test was not failing, and it ends at the next 'pass' for that same test. Repeated 'fail' logs while the test is already failing stay in the same block. Repeated 'pass' logs while the test is not failing do nothing. For every queried test ID, return the minimum fix time: the shortest duration from the first failure in any failure block to the next pass for that same block. If the test never completes a fail->pass transition, return -1. This is the batch version of the API: instead of calling methods one by one, you receive the full log history and a list of queries.

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

  1. Track, for each test, whether it is currently in a failure block and when that block started.
  2. 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

You are given a global stream of test-run logs in strictly increasing timestamp order. Each log entry is (test_id, timestamp, status), where status is either 'pass' or 'fail'. A test is considered failing from the moment it receives a 'fail' log until its next 'pass' log. Repeated 'fail' while already failing and repeated 'pass' while not failing do not change the state. For each query min_tests = k, return the longest contiguous time interval [start, end) during which at least k distinct tests are simultaneously failing. The status change at timestamp t takes effect immediately at t. Only the observed timeline is considered, so time after the last log is ignored. If multiple intervals have the same maximum length, return the one with the earliest start. If no positive-length interval exists, return [-1, -1]. This is the batch version of the follow-up API: you receive the full log history and several k-queries at once.

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

  1. First convert the logs into consecutive time segments where the number of currently failing tests is constant.
  2. 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.
Last updated: May 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement Adjacent-Line Uniq - Vanta (medium)
  • Implement a Unique Lines Command - Vanta (easy)
  • Order Classes by Prerequisites with Recursive DFS - Vanta (medium)
  • Remove Global Duplicates While Preserving Order - Vanta (medium)
  • Implement a uniq-like function - Vanta (medium)