Group Log Events Into Sessions With Max Pause and Span
Last updated: November 29, 2026
Quick Overview
Given an unordered list of log events, each with an integer timestamp and optional fields, group events that share a key field into transactions, starting a new transaction when the gap since the previous event exceeds max_pause or the total span would exceed max_span. Return each transaction's key, start, end, duration and event count.
Splunk
November 29, 20260
0
0 solved
Given an unordered list of log events, each with an integer timestamp and optional fields, group events that share a key field into transactions, starting a new transaction when the gap since the previous event exceeds max_pause or the total span would exceed max_span. Return each transaction's key, start, end, duration and event count.
This mirrors the semantics of a session-grouping search command in a log analytics product, where users stitch raw events into user sessions or request lifecycles. The interviewer checks that you pin down the boundary rules precisely, handle out-of-order input and missing keys, and keep the solution near linear after sorting.
What the Interviewer Expects
- Clarify whether the pause and span limits are inclusive and which event's timestamp the span is measured from
- Partition by key before sorting so each group is sorted independently
- Correctly close the current transaction and open a new one on either limit
- Drop or explicitly handle events that lack the key field
- State O(n log n) time and O(n) space and explain where the log factor comes from
- Return output in a deterministic order
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you do this over a stream where events arrive slightly out of order, with bounded lateness?
- How would you add a start condition and end condition (for example a login event and a logout event) to define boundaries?
- If events for one key are spread across several indexers, how would you merge partial transactions at the search head?
- How do you bound memory when millions of keys are open at once?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of events like {"ts": 12, "sid": "b"}, not sorted. Parameters: key, max_pause, max_span (seconds). A new transaction starts when t - prev > max_pause or t - start > max_span, s...
High-Level Design
- Bucket timestamps by key in a hash map, one pass.
- Sort each bucket. Sorting per key is never worse than one global sort and lets the groups be processed independently (or in parallel).
- Sweep ...