Home
← All questions

Pagination component | Frontend Machine Coding

MediumPremiumMachine Coding

Asked at Google · Amazon · LinkedIn

Frontend Machine Coding interview practice: Build offset or cursor pagination UI with ellipsis and keyboard support.

Problem

Build a pagination bar for a data table with 500 items and pageSize = 10.

Requirements

  • Show page numbers with ellipsis for large ranges (e.g. 1 … 4 5 6 … 50).
  • Prev/Next disabled at boundaries.
  • onPageChange(page) callback (1-based).
  • Highlight current page; aria-current="page".
  • (Bonus) page size selector, jump-to-page input.

Hints / Approach

  • Compute totalPages = Math.ceil(total / pageSize).
  • Generate visible page array with sliding window algorithm around current page.
  • Keep pagination controlled — parent owns currentPage.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium