
You are asked to extend a basic pagination system to support forward and backward navigation, similar to a cursor-based API.
You are given:
items
sorted in a fixed, deterministic order.
pageSize > 0
.
Design a paginator with the following operations:
getFirstPage()
→ returns the first
pageSize
items and a
cursor
representing the position after the last returned item.
getNextPage(cursor)
→ given a cursor returned by a previous call, return the next
pageSize
items and a new cursor. If there are no more items, return an empty list and a special "end" cursor.
getPrevPage(cursor)
→ given a cursor, return the
previous
page of
pageSize
items and a new cursor pointing to the start of that page. If there is no previous page, return an empty list and a "start" cursor.
Requirements:
getNextPage
.
getPrevPage
.
len(items)
is not a multiple of
pageSize
.
Implement the data structure and its methods with clear handling of indices and cursors.