Choose Non-Overlapping Ad Bookings to Maximize Total Revenue

Last updated: November 29, 2026

Quick Overview

An advertiser books exclusive takeover placements as (start, end, revenue) with half-open [start, end) times. Pick a set of non-overlapping bookings that maximizes total revenue and return that revenue.

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

0

0

0 solved


An advertiser books exclusive takeover placements as (start, end, revenue) with half-open [start, end) times. Pick a set of non-overlapping bookings that maximizes total revenue and return that revenue.

Weighted interval scheduling in the style of Meta's onsite hard coding round, framed around premium homepage takeovers that can only run one at a time. The interviewer checks that you see greedy fails once weights appear and that you combine sorting, DP, and binary search for O(n log n).

What the Interviewer Expects
  • Shows a counterexample where the earliest-end greedy loses revenue
  • Sorts by end and defines dp[i] as best revenue using the first i bookings
  • Uses binary search to find the last compatible booking
  • Writes the take-or-skip recurrence cleanly
  • Explains how to reconstruct the chosen set
Key Topics to Cover
Dynamic programming
Binary search
Weighted interval scheduling
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
  • How would you return the chosen bookings?
  • What if there are k parallel placements instead of one?
  • How would you handle bookings arriving online?
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: list of (start, end, revenue) with start < end and revenue >= 0. Output: maximum total revenue of a non-overlapping subset; touching bookings are compatible. n up to 5 * 10^4....

High-Level Design

Sort bookings by end. Let dp[i] be the best revenue using only the first i bookings in that order. For booking i (1-indexed) with start s, find j, the number of bookings whose end <= s, using bina...


Submit Your Answer
Markdown supported