Simulate Hype Train Start, Expiry, and Final Level

Last updated: November 29, 2026

Quick Overview

Given time-ordered support events (timestamp, user, points), simulate a Hype Train that starts when a minimum number of distinct users contribute within a start window, stays alive while contributions keep arriving before an expiry timeout, and ends at a level based on total points. Return each train's start, end, points and level.

Twitch
Coding & Algorithms
Software Engineer
Twitch
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given time-ordered support events (timestamp, user, points), simulate a Hype Train that starts when a minimum number of distinct users contribute within a start window, stays alive while contributions keep arriving before an expiry timeout, and ends at a level based on total points. Return each train's start, end, points and level.

Hype Trains turn subs and Bits into a shared channel event, and their rules are a small state machine with timing edge cases. Interviewers use this kind of simulation to see whether you pin down ambiguous rules before coding and keep state transitions readable.

What the Interviewer Expects
  • Asks clarifying questions about which events count toward the start and the end time
  • Models the system as two states: idle with a pending list, and active
  • Checks expiry before applying each new event
  • Counts distinct users, not events, for the start condition
  • Closes a still-active train at the end of input
Key Topics to Cover
State machine
Simulation
Sliding window
Distinct counting
Timers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you make this event-driven in production when no new event arrives to trigger expiry?
  • Two contributions land on different servers at nearly the same time. How do you keep one authoritative train per channel?
  • How would you add a cooldown so a new train cannot start for an hour after one ends?
  • How would you test the timing rules?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Rules I would confirm: a train starts when start_count distinct users contribute within start_window seconds, and the starter contributions count toward its points. While active, any contribution ...

High-Level Design

Idle state keeps a list of recent candidate events, pruned to the start window on each new event. When the distinct user count in that list reaches the threshold, switch to active with the start time ...


Submit Your Answer
Markdown supported

Related Questions