Merge Two Ranked Feed Candidate Lists Without Duplicate Videos
Last updated: November 29, 2026
Quick Overview
Two candidate generators each return a list of (video_id, score) pairs sorted by score descending. Merge them into one list sorted by score descending, keeping only the higher-scored entry when the same video appears in both.
TikTok
November 29, 20260
0
0 solved
Two candidate generators each return a list of (video_id, score) pairs sorted by score descending. Merge them into one list sorted by score descending, keeping only the higher-scored entry when the same video appears in both.
TikTok's recommendation stack blends candidates from several retrieval sources before ranking, so a simple merge question is a common phone screen opener. The interviewer checks that you can use the sorted order with two pointers and still handle duplicates correctly.
What the Interviewer Expects
- Uses two pointers to merge in linear time instead of concatenating and sorting
- Correctly deduplicates across both lists and keeps the higher score
- Explains why a seen-set suffices given descending order
- Handles uneven lengths and empty lists
- Discusses tie-breaking for equal scores
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 generalize to k candidate sources?
- What if a video can appear twice within the same list?
- How would you interleave sources to guarantee diversity instead of pure score order?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Inputs:
a,b, each a list of(video_id, score)sorted by score descending. - Output: merged list, score descending, each video once with its best score.
- Ties on score: take from
afirst fo...
High-Level Design
Classic two-pointer merge. Because both lists are descending, the first time I output a video is guaranteed to be its highest score across both lists. So I keep a seen set and skip any later occurre...