← Google Interview Insights

Google·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jul 2026

Summary

Google SWE interview with a meaty system design question around log processing and session counting. One question, lots of surface area, and I definitely didn't cover everything they wanted.

Questions Asked (1)

Q1

You have a large log file where each line is a timestamp, user ID, and action. How would you compute the number of sessions per user, where a session ends when a user's consecutive events are more than T minutes apart? Cover input format assumptions, parsing, grouping by user, handling out-of-order records, memory constraints, time and space complexity, possible optimizations, and edge cases like empty users, single events, boundary conditions at exactly T, and malformed lines.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

This thing has so many layers I didn't know where to start.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the input format and assumptions, then outline a streaming algorithm that processes lines in order, groups events by user, and counts sessions based on the time gap threshold T. Discuss trade-offs between memory and accuracy, and address edge cases and optimizations.

Pro tip: Emphasize that you would first check if the log is sorted by timestamp; if not, propose an external sort or a streaming approach with a bounded buffer, showing awareness of real-world constraints.

1. Clarify Input and Assumptions

Confirm the log format (e.g., timestamp format, delimiter), whether timestamps are in order, and the definition of a session (gap > T minutes).

2. Design Core Algorithm

For each user, track the last event timestamp; if the current event's timestamp minus last timestamp > T, increment session count. Use a hash map to store last timestamp per user.

3. Handle Out-of-Order and Memory Constraints

If records are out-of-order, either sort by timestamp (external sort if large) or use a windowed approach with a buffer. For memory, consider that the hash map size is bounded by number of unique users.

4. Analyze Complexity and Optimizations

Time: O(N) for streaming, O(N log N) if sorting. Space: O(U) where U is unique users. Optimizations: parallel processing by partitioning on user ID, or approximate counting with sketches.

5. Address Edge Cases

Discuss empty users (no events), single event (one session), exactly T gap (session continues if gap <= T), malformed lines (skip or log error), and timestamp precision.

Key Points to Mention

  • Session definition: gap > T minutes between consecutive events ends a session.
  • Use a hash map to store last event timestamp per user for O(1) updates.
  • Out-of-order records require sorting or buffering; consider external sort for large files.
  • Memory is O(U) for unique users; can be optimized with partitioning or approximate methods.
  • Time complexity: O(N) streaming, O(N log N) if sorting; space O(U).
  • Edge cases: empty input, single event, exactly T gap, malformed lines, timestamp format.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.