Debug Off-by-One Errors in a Search Results Paginator

Last updated: November 29, 2026

Quick Overview

You are given a short pagination helper that users report skips the first page and drops an item from every page. Find the bugs, fix them, and write tests that would have caught them and will catch the next one.

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

0

0

0 solved


You are given a short pagination helper that users report skips the first page and drops an item from every page. Find the bugs, fix them, and write tests that would have caught them and will catch the next one.

Google phone screens sometimes hand over buggy code and ask the candidate to debug it out loud. The interviewer watches how the candidate forms hypotheses from the symptoms, tests with tiny inputs, and writes an invariant-based test instead of only patching the specific report.

What the Interviewer Expects
  • Reads the code against the API contract (1-based pages) before changing anything
  • Explains each bug from the symptom it causes
  • Verifies with tiny hand-checkable inputs
  • Adds an invariant test: all pages concatenated equal the input
  • Covers empty input, last partial page, and out-of-range pages
Key Topics to Cover
debugging
off-by-one
invariant testing
boundary cases
pagination
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
  • How would pagination behave if items are inserted between page requests, and how do cursors fix it?
  • What should the API return for a page beyond the end?
  • How would you test this function exhaustively for small sizes?
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
  • Pages are 1-based; page 1 holds items 0..size-1.
  • Every item appears on exactly one page; the last page may be partial.
  • Return total page count for the UI.
  • Reject non-positive size and page n...
High-Level Design

Symptom 1, first page missing: start = page * size treats page as 0-based, so page 1 starts at index size. Fix: (page - 1) * size. Symptom 2, one item missing per page: the slice end `start + si...


Submit Your Answer
Markdown supported