Paginate Search Results With One Listing Per Host Per Page
Last updated: November 29, 2026
Quick Overview
Given search results already sorted by relevance as (host_id, listing_id, score) tuples, split them into pages of size k so that no host appears twice on a page when it can be avoided, while keeping relevance order as much as possible. If a page cannot be filled with distinct hosts, backfill it with the best remaining results.
Airbnb
November 29, 20260
0
0 solved
Given search results already sorted by relevance as (host_id, listing_id, score) tuples, split them into pages of size k so that no host appears twice on a page when it can be avoided, while keeping relevance order as much as possible. If a page cannot be filled with distinct hosts, backfill it with the best remaining results.
Search results on Airbnb look worse when one professional host with forty units floods the first page, so the product rule is host diversity per page. This is a classic Airbnb phone screen shape: a small, practical problem where the interviewer cares about getting the ordering rules exactly right and writing clean, bug-free code quickly.
What the Interviewer Expects
- Restate the ordering rules and confirm what happens when distinct hosts run out
- Keep deferred results in their original relevance order for later pages
- Produce a single-pass-per-page solution without repeated rescanning of the whole list
- Handle the last partial page and a list with only one host
- Explain time complexity in terms of total results and page count
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 change this if the cap were at most two listings per host per page?
- What if results arrive as a stream and you only need page p?
- How would you make the diversity rule apply across neighborhoods instead of hosts?
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 is a list sorted by score descending and a page size k. Each page should hold the highest-ranked results whose hosts are not already on that page. Results skipped because of a repeat host are no...
High-Level Design
Keep a deque of remaining results. For each page, pop from the front, accept an item if its host is new to the page, otherwise push it to a deferred deque. When the page is full or the queue is empt...