PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Applied

Track simulations and report timeouts

Last updated: Mar 29, 2026

Quick Overview

This question evaluates competency in algorithms and data-structure design for real-time stream processing, including maintaining per-simulation state, handling time-based expirations, and reasoning about performance and correctness.

  • hard
  • Applied
  • Coding & Algorithms
  • Software Engineer

Track simulations and report timeouts

Company: Applied

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

You are implementing a monitoring component for many concurrent simulations. Each simulation produces a stream of **event objects** of the form: - `sim_id` (string or integer): identifies the simulation - `type` (string): one of `"start"`, `"ping"`, or `"end"` - `timestamp` (integer or long): the event time in seconds (or milliseconds), monotonically non-decreasing across all events Semantics: - `start`: the simulation `sim_id` has started at this `timestamp`. Its **last activity timestamp** becomes this `timestamp`. - `ping`: the simulation `sim_id` is still running; update its **last activity timestamp** to this `timestamp`. - `end`: the simulation `sim_id` has finished normally at this `timestamp`; after this it should no longer be considered active. You are also given a **timeout limit** `T` (e.g., 3 seconds). A simulation should be considered **timed out** and automatically ended if: \[ \text{current_time} - \text{last\_activity\_timestamp(sim)} > T \] where `current_time` is the timestamp of the most recently processed event. Design a function with the following behavior: - The function receives events one by one in time order: `processEvent(event)`. - Upon receiving a new event with timestamp `ts_current`, it should: 1. Update internal state according to the event (`start`, `ping`, or `end`). 2. Determine which simulations have **just become timed out** at or before `ts_current`, i.e., simulations that: - Have not already ended (neither by `end` event nor by a previous timeout), and - Satisfy `ts_current - last_activity_timestamp > T`. 3. Mark these simulations as ended due to timeout so they will not be returned again. 4. Return the set (or list) of all `sim_id`s that are now considered timed out. Your function should be efficient for large numbers of simulations and events (aim for close to \(O(\log n)\) time per event, where \(n\) is the number of active simulations). Specify the data structures you would use, and describe the key operations your implementation must support (no need to provide full code). Assume the process is long-running and must handle many events over time without restarting.

Quick Answer: This question evaluates competency in algorithms and data-structure design for real-time stream processing, including maintaining per-simulation state, handling time-based expirations, and reasoning about performance and correctness.

Related Interview Questions

  • Merge Overlapping Collinear Segments - Applied (hard)
  • Implement a Fixed-Capacity Deque - Applied (medium)
  • Implement Nested Transactional Key-Value Store - Applied (hard)
  • Merge overlapping 2D line segments - Applied (medium)
  • Find intersection of two line segments - Applied (easy)
Applied logo
Applied
Dec 8, 2025, 7:32 PM
Software Engineer
Technical Screen
Coding & Algorithms
1
0

You are implementing a monitoring component for many concurrent simulations.

Each simulation produces a stream of event objects of the form:

  • sim_id (string or integer): identifies the simulation
  • type (string): one of "start" , "ping" , or "end"
  • timestamp (integer or long): the event time in seconds (or milliseconds), monotonically non-decreasing across all events

Semantics:

  • start : the simulation sim_id has started at this timestamp . Its last activity timestamp becomes this timestamp .
  • ping : the simulation sim_id is still running; update its last activity timestamp to this timestamp .
  • end : the simulation sim_id has finished normally at this timestamp ; after this it should no longer be considered active.

You are also given a timeout limit T (e.g., 3 seconds). A simulation should be considered timed out and automatically ended if:

\text{current_time} - \text{last\_activity\_timestamp(sim)} > T

where current_time is the timestamp of the most recently processed event.

Design a function with the following behavior:

  • The function receives events one by one in time order: processEvent(event) .
  • Upon receiving a new event with timestamp ts_current , it should:
    1. Update internal state according to the event ( start , ping , or end ).
    2. Determine which simulations have just become timed out at or before ts_current , i.e., simulations that:
      • Have not already ended (neither by end event nor by a previous timeout), and
      • Satisfy ts_current - last_activity_timestamp > T .
    3. Mark these simulations as ended due to timeout so they will not be returned again.
    4. Return the set (or list) of all sim_id s that are now considered timed out.

Your function should be efficient for large numbers of simulations and events (aim for close to O(log⁡n)O(\log n)O(logn) time per event, where nnn is the number of active simulations).

Specify the data structures you would use, and describe the key operations your implementation must support (no need to provide full code). Assume the process is long-running and must handle many events over time without restarting.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Applied•More Software Engineer•Applied Software Engineer•Applied Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

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

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL 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.