Keyset pagination
Implement keyset (cursor) pagination over a table ordered by (created_ts ASC, id ASC). Rows are given as [id, created_ts] (both integers, the pair is unique). Given a cursor (cursor_ts, cursor_id) and a page size `limit`, return up to `limit` rows that come strictly AFTER the cursor in the ordering — i.e. created_ts > cursor_ts, or (created_ts == cursor_ts and id > cursor_id). Return them in sorted order. A cursor of (-1, -1) means start from the beginning. Up to 50000 rows.
Implement
keyset_page(rows: list[list], cursor_ts: int, cursor_id: int, limit: int) → list[list]Examples
in
[[[1,100],[2,100],[3,200]],100,1,2]out[[2,100],[3,200]]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 25 min
solution.py
InputExpectedGot
[[[1,100],[2,100],[3,200]],100,1,2][[2,100],[3,200]]not run yetsample