A home screen shows posts from several sources in one feed, newest first, a page at a time. Each source sends feeds[f], a list of { "id": ..., "time": ... } items already sorted newest first (largest time first).
Write feedPage(feeds, offset, limit) that returns the ids of the merged feed's items at positions offset to offset + limit - 1 (positions start at 0). The merged feed is ordered by time from largest to smallest; for equal times, items from a smaller feed index come first, and within one feed the original order is kept. If the feed runs out, return the ids that exist (possibly none).
Input: feeds = [[{"id":"a1","time":90},{"id":"a2","time":50}],[{"id":"b1","time":70},{"id":"b2","time":60}]], offset = 1, limit = 2 Output: ["b1","b2"]
The merged order is a1 (90), b1 (70), b2 (60), a2 (50). Positions 1 and 2 are b1 and b2.
Input: feeds = [[{"id":"x","time":5}],[{"id":"y","time":5}]], offset = 0, limit = 5 Output: ["x","y"]
The times tie, so the item from feed 0 comes first. Only two items exist.
0 <= feeds.length <= 10^50 <= feeds[f].length <= 100010^5 items.0 <= offset, 1 <= limit <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #391 One Page of a Merged Feed. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.