Rerank a Neighborhood Feed to Cap Consecutive Posts by One Author

Last updated: November 29, 2026

Quick Overview

Given feed candidates already sorted by ranking score, each with a post id and an author, produce a feed order that is as close to score order as possible but never shows more than k posts in a row from the same author, unless no other author remains.

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

0

0

0 solved


Given feed candidates already sorted by ranking score, each with a post id and an author, produce a feed order that is as close to score order as possible but never shows more than k posts in a row from the same author, unless no other author remains.

A Nextdoor feed mixes posts from a small pool of neighbors, so one prolific poster or a business account can easily take over the top of the feed. This question checks whether you can turn a product rule (diversity) into a greedy algorithm with the right data structure and argue why it preserves ranking quality.

What the Interviewer Expects
  • Restate the rule precisely, including what happens when only one author is left
  • Choose a greedy that always takes the best eligible post
  • Use per-author queues plus a heap keyed by each author's best remaining rank
  • Temporarily hold back the blocked author and push it back after one pick
  • Give O(n log a) complexity where a is the number of authors
Key Topics to Cover
Greedy reranking
Heap
Feed diversity
Per-key queues
Constraint satisfaction
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
  • How would you extend the cap to also limit business posts in any window of 10 items?
  • What if the score gap between the blocked post and the next eligible post is huge? Would you relax the rule?
  • How do you apply this incrementally as the user scrolls and new pages are fetched?
  • How would you measure in an experiment whether the diversity rule helps?
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: list of (post_id, author, score) sorted by score descending and an integer k >= 1. Output: a permutation of post ids. At each position pick the highest-ranked remaining post whose author wo...

High-Level Design

Group posts into a FIFO queue per author (each queue is already in rank order). Keep a min-heap of (best_remaining_rank, author). Track the last author and current run length. Pop the heap: if that ...


Submit Your Answer
Markdown supported

Related Questions