Quick Overview

This question evaluates a candidate's competence in array indexing, boundary-condition handling, and simple pagination logic, focusing on correct subarray extraction and off-by-one considerations within given size constraints.

Implement basic pagination for a list

Company: Coinbase

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given: - A zero-indexed array of items `items` (you can assume it fits in memory). - An integer `pageSize > 0`. Design and implement a pagination helper that supports the following operations: 1. Initialize the paginator with the array and `pageSize`. 2. Given a **page number** `pageIndex` (0-based), return the subarray of items that belongs to that page. - Page 0 contains items with indices `[0, pageSize - 1]` (if they exist), - Page 1 contains `[pageSize, 2 * pageSize - 1]`, and so on. 3. If `pageIndex` is out of range (no items on that page), return an empty list. Assume: - `0 <= pageIndex` - `1 <= pageSize <= 10^5` - `0 <= len(items) <= 10^6` Define the interface and implement the core method(s) for pagination. Focus on clean indexing and handling boundary cases correctly.

Overview: This question evaluates a candidate's competence in array indexing, boundary-condition handling, and simple pagination logic, focusing on correct subarray extraction and off-by-one considerations within given size constraints.

Return the items for a zero-based page index, or an empty list if out of range.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([1,2,3,4,5], 2, 0)

Expected Output: [1, 2]

Explanation: First page.

Input: ([1,2,3,4,5], 2, 2)

Expected Output: [5]

Explanation: Partial final page.

Hints

  1. Use deterministic tie-breaking for prompts with multiple valid outputs.
  2. For design-style APIs, simulate operations with explicit inputs.

Basic Pagination Helper

mediumCoinbaseSoftware Engineer

Return the items for a zero-based page index, or an empty list if out of range.

View full question (all parts)

You are given:

  • A zero-indexed array of items items (you can assume it fits in memory).
  • An integer pageSize > 0.

Design and implement a pagination helper that supports the following operations:

  1. Initialize the paginator with the array and pageSize.
  2. Given a page number pageIndex (0-based), return the subarray of items that belongs to that page.
    • Page 0 contains items with indices [0, pageSize - 1] (if they exist),
    • Page 1 contains [pageSize, 2 * pageSize - 1], and so on.
  3. If pageIndex is out of range (no items on that page), return an empty list.

Assume:

  • 0 <= pageIndex
  • 1 <= pageSize <= 10^5
  • 0 <= len(items) <= 10^6

Define the interface and implement the core method(s) for pagination. Focus on clean indexing and handling boundary cases correctly.

Examples

Example 1
Input
([1,2,3,4,5], 2, 0)
Output
[1, 2]
Notes
First page.
Example 2
Input
([1,2,3,4,5], 2, 2)
Output
[5]
Notes
Partial final page.

Constraints

  • •Inputs are Python literals matching the function signature.
  • •Return a deterministic exact-match value.

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Sample call
solution([1,2,3,4,5], 2, 0)
Language
Case 1
Input
([1,2,3,4,5], 2, 0)
Expected
[1, 2]
Case 2
Input
([1,2,3,4,5], 2, 2)
Expected
[5]

Browse More Questions