Largest Uniform Ad Rate Cap Within a Promotion Budget

Last updated: November 29, 2026

Quick Overview

Sellers set ad rates (integers) on promoted listings, and a campaign has a fixed budget. Find the largest integer cap c such that the sum over listings of min(rate, c) stays within budget, or report that no cap is needed.

eBay
Coding & Algorithms
Software Engineer
eBay
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Sellers set ad rates (integers) on promoted listings, and a campaign has a fixed budget. Find the largest integer cap c such that the sum over listings of min(rate, c) stays within budget, or report that no cap is needed.

eBay's Promoted Listings let sellers choose an ad rate, and a sponsored campaign with a fixed subsidy may need to cap rates fairly. The interviewer wants you to spot a monotonic predicate and binary search on the answer, then discuss the sort plus prefix sum alternative.

What the Interviewer Expects
  • Notice spend(c) is non-decreasing in c
  • Binary search the largest feasible c with correct bounds
  • Handle the case where the full sum already fits
  • O(n log max_rate) time
  • Offer an O(n log n) sort based exact method
Key Topics to Cover
binary search on answer
monotonic predicate
prefix sums
sorting
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
  • Solve it in O(n log n) without binary search by sorting.
  • What if the cap can be a real number, not an integer?
  • How would you recompute the cap quickly when one listing's rate changes?
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

Input: bids, non-negative integers, and budget >= 0. spend(c) = sum(min(b, c)). Return the largest integer c with spend(c) <= budget. If sum(bids) <= budget, no cap binds, so return None....

High-Level Design

As c grows, each term min(b, c) stays the same or grows, so spend is monotonic. That makes the feasible caps a prefix of the integers: binary search the boundary. Bounds: spend(0) = 0 is always ...


Submit Your Answer
Markdown supported

Related Questions