Maximize Engagement From Non-Adjacent Feed Ad Slots
Last updated: November 29, 2026
Quick Overview
Each position in a user's upcoming feed has a predicted ad engagement value. Policy forbids ads in two consecutive positions. Return the maximum total engagement you can get by choosing ad positions.
TikTok
November 29, 20260
0
0 solved
Each position in a user's upcoming feed has a predicted ad engagement value. Policy forbids ads in two consecutive positions. Return the maximum total engagement you can get by choosing ad positions.
TikTok balances ad load against user experience in the For You feed, and spacing rules are a real constraint. This shows up as an easy dynamic programming question in online assessments, where the grader checks for a clean recurrence and O(1) space.
What the Interviewer Expects
- States the recurrence best[i] = max(best[i-1], best[i-2] + value[i])
- Explains the take or skip choice at each position
- Reduces space to two variables
- Handles empty, single-element and all-zero inputs
- Mentions how to recover the chosen positions
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
- What if ads must be at least k positions apart instead of 2?
- How would you return the chosen positions as well?
- What if the feed is circular, so the first and last slots are adjacent?
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: list of non-negative floats or ints
values. - Output: maximum sum of a subset with no two adjacent indices.
- Empty feed returns 0....
High-Level Design
Greedy (pick the biggest value, remove neighbors, repeat) fails, for example [3, 4, 3]: greedy picks 4, but 3 + 3 = 6 is better.
DP: let best[i] be the best total using positions 0 to i. At posit...