PracHub
QuestionsCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/OpenAI

Aggregate Recent Message Events And Active Chats

Last updated: Jul 9, 2026

Quick Overview

Prepare for a stateful event aggregation coding prompt over chat events and active chats in a rolling five-minute window. The question is useful for discussing bounded memory, window eviction, per-user active state, and how requirements change when events arrive out of order.

  • hard
  • OpenAI
  • Coding & Algorithms
  • Software Engineer

Aggregate Recent Message Events And Active Chats

Company: OpenAI

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

Build an in-memory event aggregator for chat events. Each event has `user_id`, `chat_id`, `timestamp`, and `event_type`. First, support querying the number of events in the last five minutes. Then support querying, for each user, how many chats are active in the last five minutes. A chat is active for a user if that user has a `react` event for the chat in the last five minutes and there is no later `end_chat` event for that same user and chat. Function signature: ```python class MessageEventAggregator: def add_event(self, user_id: str, chat_id: str, timestamp: int, event_type: str) -> None: pass def recent_event_count(self, now: int) -> int: pass def active_chat_count(self, user_id: str, now: int) -> int: pass ``` Constraints: - Timestamps are integer seconds. - Events may arrive in increasing timestamp order for the base version. - A follow-up may allow out-of-order events. - Memory should not grow without bound as old chats and events age out. - `event_type` is either `react` or `end_chat`. Examples: ```text add react u1 c1 at 100, react u1 c2 at 120, end_chat u1 c1 at 130; active_chat_count('u1', 150) returns 1. ``` ```text At now = 1000, events older than 700 are outside the five-minute window. ```

Quick Answer: Prepare for a stateful event aggregation coding prompt over chat events and active chats in a rolling five-minute window. The question is useful for discussing bounded memory, window eviction, per-user active state, and how requirements change when events arrive out of order.

Related Interview Questions

  • Consistent Hashing Ring with Virtual Nodes for Shard Rebalancing - OpenAI (hard)
  • Infection Spread Simulation with Death Threshold - OpenAI (medium)
  • Spreading Contagion on a Grid - OpenAI (medium)
  • Implement A Contiguous Memory Allocator With Free-Block Coalescing - OpenAI (medium)
  • Streaming Entropy with Numerical Stability - OpenAI (hard)
|Home/Coding & Algorithms/OpenAI

Aggregate Recent Message Events And Active Chats

OpenAI logo
OpenAI
Jun 5, 2026, 12:00 AM
hardSoftware EngineerOnsiteCoding & Algorithms
5
0

Build an in-memory event aggregator for chat events. Each event has user_id, chat_id, timestamp, and event_type. First, support querying the number of events in the last five minutes. Then support querying, for each user, how many chats are active in the last five minutes. A chat is active for a user if that user has a react event for the chat in the last five minutes and there is no later end_chat event for that same user and chat.

Function signature:

class MessageEventAggregator:
    def add_event(self, user_id: str, chat_id: str, timestamp: int, event_type: str) -> None:
        pass

    def recent_event_count(self, now: int) -> int:
        pass

    def active_chat_count(self, user_id: str, now: int) -> int:
        pass

Constraints:

  • Timestamps are integer seconds.
  • Events may arrive in increasing timestamp order for the base version.
  • A follow-up may allow out-of-order events.
  • Memory should not grow without bound as old chats and events age out.
  • event_type is either react or end_chat .

Examples:

add react u1 c1 at 100, react u1 c2 at 120, end_chat u1 c1 at 130; active_chat_count('u1', 150) returns 1.
At now = 1000, events older than 700 are outside the five-minute window.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 8,500+ 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
  • AI Coding 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.