PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Reddit

Merge Message Context Windows

Last updated: Apr 28, 2026

Quick Overview

This question evaluates a candidate's skill in designing efficient algorithms and appropriate data-structure use for merging overlapping message context windows and eliminating duplicates under strict time-complexity constraints.

  • medium
  • Reddit
  • Coding & Algorithms
  • Software Engineer

Merge Message Context Windows

Company: Reddit

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a chat history in which each message has a unique integer `id` and a string `content`. Message IDs are strictly increasing, and the full history is ordered by `id` in ascending order. A message is represented by this read-only model: ```java class Message { int id; String content; } ``` You are also given a provided API: ```java class Chat { /** * Returns the message with the given id, along with up to `windowSize` * messages before it and up to `windowSize` messages after it. * * The returned list is sorted by message id in ascending order. * If the given id does not exist, an empty list is returned. */ public List<Message> getChatMessages(int id, int windowSize); } ``` Implement the following class: ```java class ChatMessageMerger { ChatMessageMerger(Chat chat, int windowSize) List<Message> mergeMessages(List<Integer> ids) } ``` Requirements for `mergeMessages(ids)`: - For each input message ID, query its context window using `getChatMessages(id, windowSize)`. - Merge all returned messages into a single result. - Remove duplicates, since different context windows may overlap. - Return the final list sorted by message `id` in ascending order. - If an input ID does not exist, its query contributes nothing. Performance requirement: - Let `M` be the total number of messages returned across all API calls before deduplication. - Your algorithm must run in strictly better time than `O(M log M)`. Design and implement an efficient solution.

Quick Answer: This question evaluates a candidate's skill in designing efficient algorithms and appropriate data-structure use for merging overlapping message context windows and eliminating duplicates under strict time-complexity constraints.

Related Interview Questions

  • Solve palindrome and list tasks - Reddit (hard)
  • Implement a sliding-window rate limiter - Reddit (medium)
  • Find word sequence with 1–2 char changes - Reddit (Medium)
Reddit logo
Reddit
Jan 23, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
8
0
Loading...

You are given a chat history in which each message has a unique integer id and a string content. Message IDs are strictly increasing, and the full history is ordered by id in ascending order.

A message is represented by this read-only model:

class Message {
    int id;
    String content;
}

You are also given a provided API:

class Chat {
    /**
     * Returns the message with the given id, along with up to `windowSize`
     * messages before it and up to `windowSize` messages after it.
     *
     * The returned list is sorted by message id in ascending order.
     * If the given id does not exist, an empty list is returned.
     */
    public List<Message> getChatMessages(int id, int windowSize);
}

Implement the following class:

class ChatMessageMerger {
    ChatMessageMerger(Chat chat, int windowSize)
    List<Message> mergeMessages(List<Integer> ids)
}

Requirements for mergeMessages(ids):

  • For each input message ID, query its context window using getChatMessages(id, windowSize) .
  • Merge all returned messages into a single result.
  • Remove duplicates, since different context windows may overlap.
  • Return the final list sorted by message id in ascending order.
  • If an input ID does not exist, its query contributes nothing.

Performance requirement:

  • Let M be the total number of messages returned across all API calls before deduplication.
  • Your algorithm must run in strictly better time than O(M log M) .

Design and implement an efficient solution.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

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

Master your tech interviews with 7,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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.