Paginate Search Listings
Asked at Airbnb
Reported by the problem's creator, not verified
A search returns listings ordered from best to worst score. Each listing is a pair [listing_id, host_id]. A page shows page_size listings, and the same host should not appear twice on one page when that can be avoided.
Examples
Example 1
Input: listings =
[[1,1],[2,1],[3,2],[4,3],[5,2],[6,1],[7,4],[8,5]], page_size =3Output:
[[1,3,4],[2,5,7],[6,8]]Explanation: Page 1 scans listings 1 to 8 and takes 1 (host 1), skips 2 (host 1 again), then takes 3 (host 2) and 4 (host 3), giving [1, 3, 4]. Page 2 starts from the remaining 2, 5, 6, 7, 8 and takes 2 (host 1), 5 (host 2), 7 (host 4), giving [2, 5, 7]. Page 3 holds the last two listings, 6 and 8, whose hosts differ.