PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's ability to implement time-based broadcast delivery, including filtering by time windows, idempotent state updates to prevent duplicate sends, and managing concurrency and data structures for processing and tracking broadcast logs.

  • medium
  • Attentive
  • Coding & Algorithms
  • Software Engineer

Implement Due Broadcast Sender

Company: Attentive

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are building a notification system. You are given: - A mapping from `company_id` to a list of subscriber IDs. - A list of broadcast logs. Each log contains: - `log_id` - `company_id` - `message` - `scheduled_at` - a flag or status indicating whether it has already been sent. - A helper function `send_subscriber_msg(subscriber_id, message)`. Implement code that sends a broadcast message to all subscribers of the specified company when the broadcast becomes due. Your design should support two variants: 1. The function receives a single `current_time` and should send all broadcasts with `scheduled_at <= current_time` that have not yet been processed. 2. The function receives a time window `[start_time, end_time]` and should send all broadcasts whose scheduled time falls within that range. Clarify the input structures you choose, how you avoid duplicate sends, and how you update processing state after delivery.

Quick Answer: This question evaluates a candidate's ability to implement time-based broadcast delivery, including filtering by time windows, idempotent state updates to prevent duplicate sends, and managing concurrency and data structures for processing and tracking broadcast logs.

Part 1: Send Due Broadcasts Up To current_time

You are building a notification system for multiple companies. Each company has a list of subscriber IDs, and each broadcast log describes one message that may need to be sent. Implement a function that processes all broadcast logs whose `scheduled_at` time is less than or equal to `current_time`, but only if they have not already been sent. Because coding platforms usually cannot verify real side effects, simulate `send_subscriber_msg(subscriber_id, message)` by recording each delivery as a tuple `(subscriber_id, log_id, message)`. Rules: - Process logs in their original order. - For each due, unsent log, send the message to all subscribers of that log's company, in the order stored in the subscriber list. - After processing a due log, mark it as `sent = True`. - If a company has no subscribers, the log is still considered processed and must still be marked as sent. - Return the generated deliveries and the updated logs. - Do not rely on mutating the caller's input; return the updated state explicitly.

Constraints

  • 0 <= number of companies <= 10^4
  • 0 <= number of logs <= 10^4
  • The total number of subscriber IDs across all companies is <= 10^5
  • 0 <= scheduled_at, current_time <= 10^9
  • Each `log_id` is unique
  • Subscriber IDs within one company's list are distinct

Examples

Input: ({1: [101, 102], 2: [201]}, [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': False}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': False}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 4, 'sent': True}], 5)

Expected Output: ([(101, 1, 'A'), (102, 1, 'A')], [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': True}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': False}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 4, 'sent': True}])

Explanation: Only log 1 is both due and unsent at time 5. Log 2 is not due yet, and log 3 was already sent.

Input: ({1: [7], 2: [8, 9]}, [{'log_id': 10, 'company_id': 2, 'message': 'Sale', 'scheduled_at': 1, 'sent': False}, {'log_id': 11, 'company_id': 1, 'message': 'Ping', 'scheduled_at': 3, 'sent': False}], 10)

Expected Output: ([(8, 10, 'Sale'), (9, 10, 'Sale'), (7, 11, 'Ping')], [{'log_id': 10, 'company_id': 2, 'message': 'Sale', 'scheduled_at': 1, 'sent': True}, {'log_id': 11, 'company_id': 1, 'message': 'Ping', 'scheduled_at': 3, 'sent': True}])

Explanation: Both logs are due by time 10, so both are delivered in log order.

Input: ({1: [1]}, [{'log_id': 5, 'company_id': 99, 'message': 'Ghost', 'scheduled_at': 2, 'sent': False}], 2)

Expected Output: ([], [{'log_id': 5, 'company_id': 99, 'message': 'Ghost', 'scheduled_at': 2, 'sent': True}])

Explanation: The company has no subscribers, so no deliveries are recorded, but the due log is still marked sent.

Input: ({}, [], 100)

Expected Output: ([], [])

Explanation: Edge case: no companies and no logs.

Hints

  1. For each log, first decide whether it is both due and unsent before generating any deliveries.
  2. To avoid duplicate sends in future calls, mark a log as sent immediately after processing it, even if it had no subscribers.

Part 2: Send Broadcasts Inside an Inclusive Time Window

You are building a notification system for multiple companies. Each company has a list of subscriber IDs, and each broadcast log describes one scheduled message. Implement a function that processes all broadcast logs whose `scheduled_at` time falls within the inclusive range `[start_time, end_time]`, but only if they have not already been sent. Because coding platforms usually cannot verify real side effects, simulate `send_subscriber_msg(subscriber_id, message)` by recording each delivery as a tuple `(subscriber_id, log_id, message)`. Rules: - A log should be processed only if `start_time <= scheduled_at <= end_time` and `sent == False`. - Process logs in their original order. - For each qualifying log, send the message to all subscribers of that log's company, in the order stored in the subscriber list. - After processing a qualifying log, mark it as `sent = True`. - If a company has no subscribers, the log is still considered processed and must still be marked as sent. - Return the generated deliveries and the updated logs. - Do not rely on mutating the caller's input; return the updated state explicitly.

Constraints

  • 0 <= number of companies <= 10^4
  • 0 <= number of logs <= 10^4
  • The total number of subscriber IDs across all companies is <= 10^5
  • 0 <= start_time <= end_time <= 10^9
  • Each `log_id` is unique
  • Subscriber IDs within one company's list are distinct

Examples

Input: ({1: [101, 102], 2: [201]}, [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': False}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': False}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 10, 'sent': False}], 5, 8)

Expected Output: ([(101, 1, 'A'), (102, 1, 'A'), (201, 2, 'B')], [{'log_id': 1, 'company_id': 1, 'message': 'A', 'scheduled_at': 5, 'sent': True}, {'log_id': 2, 'company_id': 2, 'message': 'B', 'scheduled_at': 8, 'sent': True}, {'log_id': 3, 'company_id': 1, 'message': 'C', 'scheduled_at': 10, 'sent': False}])

Explanation: Logs scheduled at 5 and 8 are inside the inclusive window [5, 8]. Log 3 is outside.

Input: ({1: [7]}, [{'log_id': 1, 'company_id': 1, 'message': 'X', 'scheduled_at': 6, 'sent': True}, {'log_id': 2, 'company_id': 1, 'message': 'Y', 'scheduled_at': 9, 'sent': False}], 6, 9)

Expected Output: ([(7, 2, 'Y')], [{'log_id': 1, 'company_id': 1, 'message': 'X', 'scheduled_at': 6, 'sent': True}, {'log_id': 2, 'company_id': 1, 'message': 'Y', 'scheduled_at': 9, 'sent': True}])

Explanation: Log 1 is in the time window but is already sent, so only log 2 is processed.

Input: ({3: [30, 31]}, [{'log_id': 4, 'company_id': 3, 'message': 'Exact', 'scheduled_at': 12, 'sent': False}, {'log_id': 5, 'company_id': 3, 'message': 'Late', 'scheduled_at': 13, 'sent': False}], 12, 12)

Expected Output: ([(30, 4, 'Exact'), (31, 4, 'Exact')], [{'log_id': 4, 'company_id': 3, 'message': 'Exact', 'scheduled_at': 12, 'sent': True}, {'log_id': 5, 'company_id': 3, 'message': 'Late', 'scheduled_at': 13, 'sent': False}])

Explanation: Edge case: start and end times are equal, so only logs exactly at time 12 are processed.

Input: ({1: [1]}, [{'log_id': 6, 'company_id': 9, 'message': 'NoList', 'scheduled_at': 2, 'sent': False}], 1, 3)

Expected Output: ([], [{'log_id': 6, 'company_id': 9, 'message': 'NoList', 'scheduled_at': 2, 'sent': True}])

Explanation: The log is inside the window, but the company has no subscribers. It is still marked as sent.

Input: ({}, [], 0, 0)

Expected Output: ([], [])

Explanation: Edge case: no companies and no logs.

Hints

  1. The window is inclusive, so broadcasts exactly at `start_time` or `end_time` should be processed.
  2. Keep the filtering condition separate from the delivery loop: first decide whether a log belongs in the window and is unsent, then send it.
Last updated: Apr 19, 2026

Related Coding Questions

  • Remove Repeated Character Groups - Attentive (medium)

Loading coding console...

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.