Problem · Array
Cursor-Based Pagination Over Sorted Logs
Learn this problemProblem statement
You are given logsByUser, where logsByUser[u] is the sorted list of log timestamps for user u.
A cursor-based paginator should return the next pageSize unread logs across all users in globally sorted order, then advance the cursor so the following call resumes from the next unread log.
For this FastPrep draft, implement the same cursor behavior as a single function: starting from the initial cursor, return every page that would be produced by repeatedly calling the paginator until no logs remain.
When two users have the same timestamp, emit the smaller user index first. The final page may contain fewer than pageSize logs. If logsByUser contains no logs or pageSize <= 0, return an empty array.
Function
paginateSortedLogs(logsByUser: int[][], pageSize: int) → int[][]Examples
Example 1
logsByUser = [[1, 2, 9, 10, 11], [4, 5, 6, 7, 8]]pageSize = 3return = [[1, 2, 4], [5, 6, 7], [8, 9, 10], [11]]The global sorted merge is [1, 2, 4, 5, 6, 7, 8, 9, 10, 11]. Repeated cursor calls with count 3 return the next slice each time.
Example 2
logsByUser = [[], [1, 2, 3], []]pageSize = 10return = [[1, 2, 3]]Empty user log lists are skipped. Because pageSize is larger than the remaining logs, all logs appear in one page.
Example 3
logsByUser = [[1, 5], [1, 5]]pageSize = 4return = [[1, 1, 5, 5]]Duplicate timestamps are allowed. Equal timestamps are emitted in stable user-index order.
Constraints
0 <= logsByUser.length- Each
logsByUser[u]is sorted in nondecreasing order. pageSizemay be any integer.- The cursor state can be represented by the next unread index for each user.
More Roblox problems
- Most Frequent Call Stack Per ThreadPHONE SCREEN · Seen Jul 2026
- Break a PalindromeOA · Seen Jun 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · Seen Jun 2026
- Closest Binary Search Tree Value — Base PracticePHONE SCREEN · Seen Jun 2026
- Design Search Autocomplete SystemPHONE SCREEN · Seen Jun 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Maximum Number of Balls in a BoxPHONE SCREEN · Seen Jun 2026