Simulate Gift Combo Streaks in a LIVE Room

Last updated: November 29, 2026

Quick Overview

In TikTok LIVE, a viewer who sends the same gift again within 3 seconds of their previous one extends a combo shown on screen. Given gift events `(ts, user, gift)`, return every combo of length at least 2 as `(user, gift, length, start_ts)` ordered by start time.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


In TikTok LIVE, a viewer who sends the same gift again within 3 seconds of their previous one extends a combo shown on screen. Given gift events `(ts, user, gift)`, return every combo of length at least 2 as `(user, gift, length, start_ts)` ordered by start time.

Simulation problems tied to LIVE features are common in TikTok's online assessment. The grader checks that you keep independent state per key, close streaks at the right moment (including at the end of input), and order the output deterministically.

What the Interviewer Expects
  • Keys state by (user, gift) so different gifts or users never interfere
  • Applies the gap rule against the previous event of the same key, not the combo start
  • Flushes still-open combos at end of stream
  • Sorts input defensively and output deterministically
  • Clear inclusive versus exclusive gap boundary
Key Topics to Cover
simulation
hash maps
event processing
sliding gap windows
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 emit combos in real time as they end, without waiting for the stream to finish?
  • How would you bound memory when millions of keys go idle?
  • What if events can arrive up to two seconds late?
  • How would this change if any gift type keeps the combo alive?
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

A combo is a maximal run of events for one (user, gift) pair where each consecutive gap is at most 3 seconds (inclusive, which I confirm). Only runs of length 2 or more are reported. Output tuples `(u...

High-Level Design

Process events in time order with a dictionary from key to [start, last, count]. For each event: if there is an active run and ts - last <= gap, extend it. Otherwise the old run (if any) is finish...


Submit Your Answer
Markdown supported

Related Questions