Group A Creator's Generations Into Idle-Gap Sessions

Last updated: November 29, 2026

Quick Overview

Given unsorted (user_id, timestamp) generation events, split each user's events into sessions whenever the gap between consecutive generations exceeds 30 minutes, and return each user's session count and the most generations in a single session.

Luma AI
Coding & Algorithms
Software Engineer
Luma AI
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given unsorted (user_id, timestamp) generation events, split each user's events into sessions whenever the gap between consecutive generations exceeds 30 minutes, and return each user's session count and the most generations in a single session.

Dream Machine users iterate in bursts (prompt, tweak, extend), so product and growth teams care about sessions rather than raw generation counts. This screen checks grouping, sorting and off-by-one handling of the gap boundary.

What the Interviewer Expects
  • Group events by user before sorting
  • Sort each user's timestamps
  • Use a strict greater-than for the gap rule and say so
  • Track current and longest session length in one pass
  • Discuss duplicates and empty input
Key Topics to Cover
Sessionization
Sorting
Hash maps
Single pass
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 compute this as a streaming job where events arrive out of order?
  • How would you express the same logic in SQL with window functions?
  • Should the 30 minute threshold differ for the iOS app and the web app?
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

Input list of (user, ts) in seconds, any order. A new session starts when cur - prev > 1800. Output {user: (sessions, longest_session_size)}....

High-Level Design

Bucket timestamps by user in a dict, sort each bucket, then walk adjacent pairs. Every gap above the threshold closes a session; otherwise the current session grows....


Submit Your Answer
Markdown supported

Related Questions