Maximize Promoted Pin Revenue with a Minimum Feed Spacing Rule
Last updated: November 29, 2026
Quick Overview
Each slot in a home feed has an expected revenue if a promoted Pin is placed there, and policy requires at least gap organic Pins between any two promoted Pins. Choose slots to maximize total expected revenue and return the chosen slots.
0
0
0 solved
Each slot in a home feed has an expected revenue if a promoted Pin is placed there, and policy requires at least gap organic Pins between any two promoted Pins. Choose slots to maximize total expected revenue and return the chosen slots.
Ads load in the Pinterest home feed is governed by spacing rules that protect user experience, and the ads team needs an allocator that respects them. This is a generalized house robber problem: the interviewer checks the recurrence, off-by-one handling of the gap, and reconstruction of the actual slots.
What the Interviewer Expects
- Defines dp over prefixes with a clear meaning
- Gets the gap jump right so slots i and j satisfy j - i > gap
- Reconstructs chosen slots, not just the value
- Handles gap of zero and empty input
- Discusses why a greedy pick of the top slots fails
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
- How would you add a cap of at most M promoted Pins per page?
- What if the revenue of a slot depends on which ad goes there, with each ad used once?
- How would this change for a two-column masonry grid where spacing is measured in screen distance?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- values: non-negative expected revenue per slot. gap >= 0.
- Two chosen slots i < j must satisfy j - i >= gap + 1.
- Output (best_total, slots). Empty feed returns (0, [])....
High-Level Design
Let dp[i] be the best revenue using only slots 0..i-1. For slot i-1 we either skip it (dp[i-1]) or take it, which forbids the previous gap slots, so we add dp[i-1-gap] (or 0 if that index is negative)...