Smallest Batch Size That Keeps SQS Message Batches Under a Limit

Last updated: November 29, 2026

Quick Overview

Each queue has a backlog of messages. With batch size b, queue i needs ceil(backlog[i] / b) batches. Return the smallest positive integer b such that the total number of batches across all queues is at most a given limit.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

0

0 solved


Each queue has a backlog of messages. With batch size b, queue i needs ceil(backlog[i] / b) batches. Return the smallest positive integer b such that the total number of batches across all queues is at most a given limit.

An approachable binary-search-on-answer item for Amazon's online assessment, phrased around batching messages from Amazon SQS-style queues to respect a per-minute API call budget. The interviewer checks the monotonic function and correct bounds.

What the Interviewer Expects
  • See that a larger batch size never increases total batches
  • Search b in [1, max(backlog)]
  • Use integer ceiling division
  • Return the first feasible value
  • State O(n log max) time
Key Topics to Cover
binary search on answer
ceiling division
monotonic predicate
rate limits
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
  • What if there were also a maximum allowed batch size?
  • How would you handle the limit being smaller than the number of queues?
  • What if each queue had a different per-batch overhead cost?
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

Inputs: list of positive integers backlog (n of them) and integer limit with limit >= n. Output: smallest b >= 1 with sum(ceil(x / b)) <= limit. b = max(backlog) always gives exactly n batches, so a s...

High-Level Design

total(b) = sum of ceil(x / b) is non-increasing in b, so the set of feasible b values is a suffix of the integers. Binary search the lower bound in [1, max(backlog)]: if total(mid) <= limit, the answe...


Submit Your Answer
Markdown supported