Debug an Off-By-One Cursor in Paginated Connections API

Last updated: November 29, 2026

Quick Overview

A teammate's function pages through a member's connections sorted by id using an 'after' cursor, but clients report missing and duplicated connections at page boundaries. Find the bugs, fix the function, and write tests that would have caught them.

LinkedIn
Software Engineering Fundamentals
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

0

0 solved


A teammate's function pages through a member's connections sorted by id using an 'after' cursor, but clients report missing and duplicated connections at page boundaries. Find the bugs, fix the function, and write tests that would have caught them.

Paginated REST APIs are everywhere at LinkedIn (Rest.li collections use start and count or cursors). This debugging question checks whether you reason about boundary conditions methodically and write targeted tests instead of eyeballing.

What the Interviewer Expects
  • Reproduces the bug with a tiny input before changing code
  • Identifies the inclusive versus exclusive cursor mistake
  • Identifies the off-by-one in the has-more check
  • Writes tests for empty list, exact multiple of page size, and paging through all items
  • Mentions why cursors beat offsets when data changes between requests
Key Topics to Cover
debugging
pagination
off-by-one
unit testing
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • What happens to offset pagination if a connection is removed between page requests?
  • How would you encode the cursor so clients cannot tamper with it?
  • How would you test pagination against a live, changing dataset?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

The buggy version, given ids sorted ascending, after (last id the client saw, or None), and limit:

def page_buggy(ids, after, limit): start = 0 if after is None else bisect_left(i...
High-Level Design

Reproduce with ids = [1,2,3,4], limit = 2. Page 1 returns [1,2], has_more = 2 < 3 True. Page 2 with after = 2: bisect_left finds the index of 2 itself, so it returns [2,3]: a duplicate. ...


Submit Your Answer
Markdown supported