Simulate Priority Campaign Throughput on Shared Short Codes

Last updated: November 29, 2026

Quick Overview

Several campaigns share sending numbers, and each number can send a fixed number of messages per second. Higher-priority campaigns preempt lower ones and leftover capacity in a second flows to the next campaign. Return the second in which each campaign sends its last message, efficiently even when campaigns have millions of recipients.

Attentive
Coding & Algorithms
Software Engineer
Attentive
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Several campaigns share sending numbers, and each number can send a fixed number of messages per second. Higher-priority campaigns preempt lower ones and leftover capacity in a second flows to the next campaign. Return the second in which each campaign sends its last message, efficiently even when campaigns have millions of recipients.

Attentive's messaging platform must push billions of texts through carrier and aggregator throughput limits, so a flash-sale campaign and an abandoned-cart flow compete for the same lane. This onsite coding problem checks whether the candidate avoids a per-second simulation and reasons about event-driven time with a priority queue.

What the Interviewer Expects
  • Recognize that per-second or per-message simulation is too slow for large counts
  • Process each sender independently
  • Model capacity as a stream of slots so partial seconds are handled exactly
  • Advance time only to the next arrival or completion, using a heap keyed on priority
  • Get tie-breaking and the finish-second formula right
  • Reach O(n log n) for n campaigns
Key Topics to Cover
Event-driven simulation
Priority queue
Rate limiting
Preemptive scheduling
Integer time modeling
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would weighted fair sharing between equal-priority campaigns change the design?
  • What if a sender's rate changes at known times, for example carrier throttling during peak?
  • How would you also enforce quiet hours that pause some recipients?
  • How would you turn this into an ETA shown to a marketer before launch?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Each campaign is (id, sender, start_second, count, priority), and rate[sender] is messages per second. Within a second, capacity goes to the highest priority first. Ties go to the earlier start an...

High-Level Design

Senders never interact, so group by sender. On one sender, number the capacity slots: slot k falls in second k // r, and a campaign starting at second s can use slots from s * r onward. Under ...


Submit Your Answer
Markdown supported

Related Questions