Space Out Posts From the Same Creator So No Two Are Adjacent
Last updated: November 29, 2026
Quick Overview
Given a list of feed posts labeled by creator ID, reorder them so no two consecutive posts come from the same creator, or return an empty list if that is impossible.
Meta
November 29, 20260
0
0 solved
Given a list of feed posts labeled by creator ID, reorder them so no two consecutive posts come from the same creator, or return an empty list if that is impossible.
Feed diversity is a real ranking constraint at Meta, so this onsite coding question dresses up the classic rearrangement problem as a News Feed post-processing step. The interviewer looks for the greedy insight (always place the most frequent creator that is not blocked) and a correct impossibility check.
What the Interviewer Expects
- Count posts per creator
- Greedily emit the most frequent creator not used in the previous slot
- Use a max-heap and hold back the last used creator for one step
- Detect impossibility when the top creator exceeds ceil(n/2)
- Analyze O(n log c) time
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
- Generalize to: no creator repeats within any window of d posts.
- What if you must keep the ranking order as stable as possible?
- How would you do this in O(n) using the even/odd index fill trick?
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 creator IDs, one per post, for example
[a, a, b, b, c, a]. - Output: a permutation where
result[i] != result[i+1]for all i, or[]if none exists. - Any valid arrangement is acc...
High-Level Design
Greedy: at every slot place the creator with the most remaining posts among those that did not fill the previous slot. Placing high-frequency creators early keeps them from piling up at the end wh...