Reorder a Feed Batch So No Creator Appears Twice in a Row

Last updated: November 29, 2026

Quick Overview

The For You feed receives a batch of ranked candidate videos, each with a creator id. Reorder the batch so no two adjacent videos share a creator, keeping each creator's own videos in their original relative order, or return None if that is impossible.

TikTok
Coding & Algorithms
Software Engineer
TikTok
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


The For You feed receives a batch of ranked candidate videos, each with a creator id. Reorder the batch so no two adjacent videos share a creator, keeping each creator's own videos in their original relative order, or return None if that is impossible.

Feed diversity rules are a real part of TikTok's ranking pipeline, and this greedy problem is a frequent screen question. The interviewer checks the feasibility condition, the max-heap greedy that always places the most frequent eligible creator, and how you would relax it when ranking order also matters.

What the Interviewer Expects
  • States the impossibility condition: some creator has more than ceil(n/2) videos
  • Greedy with a max-heap by remaining count, skipping the previous creator
  • Preserves each creator's internal ordering with per-creator queues
  • Explains why picking the most frequent creator avoids getting stuck
  • Discusses the tension with rank order and windowed diversity constraints
Key Topics to Cover
greedy
heaps
feed diversity
rearrangement
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
  • Generalize to: the same creator must be at least k positions apart.
  • How would you keep the result as close as possible to the original ranking?
  • What should the product do when the constraint is infeasible?
  • How would you apply this to an infinite feed rather than a fixed batch?
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: ordered list of (video_id, creator). Output: a permutation of video ids with no equal adjacent creators, each creator's videos in their original order, or None. Feasible exactly when the larges...

High-Level Design

Group videos into a queue per creator. Put (-remaining, creator) into a max-heap. Repeatedly pop the creator with the most remaining videos; if it is the one just placed, pop the next instead and pu...


Submit Your Answer
Markdown supported