PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/xAI

Compute total active time per Twitter Space

Last updated: Jun 13, 2026

Quick Overview

This question evaluates a candidate's ability to perform event-log sessionization and time-interval aggregation across users and spaces, testing skills in algorithms, state management, and event processing within the Coding & Algorithms domain.

  • medium
  • xAI
  • Coding & Algorithms
  • Software Engineer

Compute total active time per Twitter Space

Company: xAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given an event log of user activity in Twitter Spaces. Each record has: - `operation`: one of `create`, `join`, `leave` - `space_id`: identifier of the space (string) - `user_id`: identifier of the user (string) - `timestamp`: Unix timestamp in seconds (integer) A user is considered **in a space** from the time they `join` until they `leave`. The `create` operation means the user created the space and is **also considered to have joined at that timestamp**. ### Task Return the **total active time (in seconds)** for each space, defined as: > sum over all users of (time that user spent in that space) A user may join/leave the same space multiple times; all sessions should be summed. ### Example Input records: - `["create", "abc", "user_1", 1234567000]` - `["join", "abc", "user_2", 1234567100]` - `["leave", "abc", "user_2", 1234567300]` - `["create", "def", "user_2", 1234568000]` - `["leave", "def", "user_2", 1234568500]` - `["leave", "abc", "user_1", 1234569000]` Output: - `{ "abc": 2200, "def": 500 }` Explanation: `user_1` spent `2000` seconds in `abc`, `user_2` spent `200` seconds in `abc`, and `user_2` spent `500` seconds in `def`. ### Follow-up (real-time) Design a data structure / approach that can continuously output the **top-k spaces by current active user count** (i.e., number of users currently in the space), with updates arriving as join/leave events stream in.

Quick Answer: This question evaluates a candidate's ability to perform event-log sessionization and time-interval aggregation across users and spaces, testing skills in algorithms, state management, and event processing within the Coding & Algorithms domain.

Related Interview Questions

  • Flatten and unflatten nested Python structures - xAI (nan)
  • Compute dasher pay from order events - xAI (nan)
  • Design a Recoverable Iterator - xAI (medium)
  • Implement Distributed Matrix Multiplication - xAI (hard)
  • Find kth element and sliding-window kth in stream - xAI (hard)
xAI logo
xAI
Feb 11, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
16
0
Practice Read
Loading...

You are given an event log of user activity in Twitter Spaces. Each record has:

  • operation : one of create , join , leave
  • space_id : identifier of the space (string)
  • user_id : identifier of the user (string)
  • timestamp : Unix timestamp in seconds (integer)

A user is considered in a space from the time they join until they leave. The create operation means the user created the space and is also considered to have joined at that timestamp.

Task

Return the total active time (in seconds) for each space, defined as:

sum over all users of (time that user spent in that space)

A user may join/leave the same space multiple times; all sessions should be summed.

Example

Input records:

  • ["create", "abc", "user_1", 1234567000]
  • ["join", "abc", "user_2", 1234567100]
  • ["leave", "abc", "user_2", 1234567300]
  • ["create", "def", "user_2", 1234568000]
  • ["leave", "def", "user_2", 1234568500]
  • ["leave", "abc", "user_1", 1234569000]

Output:

  • { "abc": 2200, "def": 500 }

Explanation: user_1 spent 2000 seconds in abc, user_2 spent 200 seconds in abc, and user_2 spent 500 seconds in def.

Follow-up (real-time)

Design a data structure / approach that can continuously output the top-k spaces by current active user count (i.e., number of users currently in the space), with updates arriving as join/leave events stream in.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More xAI•More Software Engineer•xAI Software Engineer•xAI Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.