Cursor-Based Pagination Over Sorted Logs
Updated
Problem 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 Onsite Interview questions
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Sliding Window: Target Containment and Most-Repeated WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Weighted Server Load Balancer with TTLStripe · ONSITE INTERVIEWStripe interview questions
- Meeting Rooms III: Most Booked RoomGoogle · ONSITE INTERVIEWGoogle interview questions
- Shortest-Job-First Process SchedulingByteDance · PHONE SCREENByteDance interview questions
- Meeting Rooms IIIBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
- Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
- Generate Complete Inputs for a Supplied ClassifierGeneral Motors · ONSITE INTERVIEW
- Minimum Meeting Rooms Without a Sweep LineGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
- Merge Sort Report with a Noisy ComparatorMercor · ONSITE INTERVIEWMercor interview questions
Interview reports that mention this question
Roblox interview experiences
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)