bugger.
All challenges/JavaScriptmediummeta-feed-pagination-v1
THE INVESTIGATION

The feed page that skips tied posts

A feed cursor skips unread posts when several posts share the same timestamp.

Meta-styleInterview practicePagination

What’s going wrong

Original Meta-style interview practice. This is not an actual Meta interview question. Bugger does not provide an AI assistant.

The first feed page is correct, but the next page silently loses posts created at the same instant as its final item. Repair the cursor boundary while keeping a stable feed order.

Input is {"posts":[{"id":"a","timestamp":10},...],"cursor":null,"limit":2}. Sort posts by descending timestamp and then ascending ID using ASCII string order. A non-null cursor is {"timestamp":10,"id":"a"} and marks an exclusive boundary in that same order. Return the first limit posts strictly after that pair, even if the cursor’s post is no longer present in posts.

Print {"ids":[...],"nextCursor":...,"hasMore":false}. nextCursor is the timestamp/ID pair of the last returned post, or null for an empty page. hasMore is true exactly when eligible posts remain beyond the returned page. Input has at most 200 posts with distinct nonempty IDs containing ASCII letters, digits, underscores or hyphens. Timestamps are integers from 0 to 1000000000; limit is an integer from 1 to 50. The cursor is null or a pair in those domains. Fix comesAfter without changing the ordering contract.

Expected behavior

Use the complete ordering key for the exclusive cursor boundary, preserving tied posts without repeating the cursor item.

Reproduction

01 Continue through a tied timestamp
{"posts":[{"id":"c","timestamp":9},{"id":"b","timestamp":10},{"id":"a","timestamp":10}],"cursor":{"id":"a","timestamp":10},"limit":2}
{"ids":["b","c"],"nextCursor":{"id":"c","timestamp":9},"hasMore":false}
02 First page without a cursor
{"posts":[{"id":"b","timestamp":9},{"id":"a","timestamp":10}],"cursor":null,"limit":1}
{"ids":["a"],"nextCursor":{"id":"a","timestamp":10},"hasMore":true}
03 Cursor item is excluded
{"posts":[{"id":"a","timestamp":10},{"id":"b","timestamp":9}],"cursor":{"id":"a","timestamp":10},"limit":1}
{"ids":["b"],"nextCursor":{"id":"b","timestamp":9},"hasMore":false}

Before you begin

  • Array sorting
  • Comparison predicates
  • Cursor pagination

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.