Highest Revenue K-Day Window With No Repeated Advertiser
Last updated: November 29, 2026
Quick Overview
Given a list of (advertiser, revenue) entries, one per day, and a window size k, return the maximum total revenue over any k consecutive days in which no advertiser appears twice, or 0 if no such window exists.
Meta
November 29, 20260
0
0 solved
Given a list of (advertiser, revenue) entries, one per day, and a window size k, return the maximum total revenue over any k consecutive days in which no advertiser appears twice, or 0 if no such window exists.
Combines a fixed-size sliding window with a distinctness constraint, framed around ad sponsorship slots. A Meta interviewer uses it to see whether you can maintain two pieces of window state (a sum and a count map) in lockstep.
What the Interviewer Expects
- Slides a window of exact length k
- Maintains a running revenue sum and an advertiser count map together
- Checks distinctness by comparing the number of keys with k
- Deletes advertisers from the map when their count drops to zero
- Gives O(n) time and O(k) space
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Drop the fixed size: find the max revenue window of any length with distinct advertisers.
- Allow each advertiser at most twice in the window.
- What if revenues can be negative?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: days, a list of (advertiser_id, revenue) tuples with non-negative revenue, and k >= 1. Output: the maximum sum of revenue over windows of exactly k consecutive days whose advertiser IDs a...
High-Level Design
Move a right pointer across the days. Add the incoming revenue and increment its advertiser count. Once the window has more than k days, subtract the outgoing revenue and decrement its count, deleting...