← Questions

Responsive grid of fixed-size boxes

0
AmazonCodingLast asked Jan 2026

A coding interview question asked in Amazon's technical phone screen, last asked Jan 2026. It tests frontend, css and layout.

Build a page that lays out many fixed-size boxes in a grid that reflows with the window: each row holds as many boxes as fit, and the rest wrap to new rows. Explain the CSS you use, how the layout behaves on very narrow and very wide screens, and how you would keep it fast with thousands of boxes.

Interface

Unless you agree on a different interface with the interviewer, assume:

  • <BoxGrid items={items} /> — a React component; each item renders as a box exactly 200 × 150 px, with 16 px gaps between boxes.

Example

container 1000px wide  ->  4 boxes per row    # 4 × 200 + 3 × 16 = 848 fits; 5 needs 1064
container 650px wide   ->  3 per row          # 3 × 200 + 2 × 16 = 632
container 400px wide   ->  1 per row
container 180px wide   ->  1 per row, box overflows or scales (decide which)

Constraints

  • Boxes keep their size; no horizontal page scroll.
  • Up to 10,000 items.

Clarifying questions

  • Should leftover space be spread between boxes, or should the grid be centered?
  • What happens when the window is narrower than one box?
  • Do boxes hold interactive content (focusable)?
  • Must it support old browsers?

What a strong answer covers

  • CSS Grid with grid-template-columns: repeat(auto-fill, 200px) and gap: 16px (or flexbox with flex-wrap: wrap), and the difference between auto-fill and auto-fit.
  • Centering with justify-content, and a rule for the narrow case (minmax, max-width: 100%).
  • No JavaScript needed for layout; container queries if the grid sits in a resizable panel.
  • Thousands of items: virtualize rows (compute columns from the container width with a ResizeObserver), stable keys, memoized items.
  • Accessibility: a list structure (ul/li or role="list"), visible focus, reading order matching visual order.

Follow-ups

  • Boxes of different heights: masonry layout.
  • Keyboard navigation with arrow keys between boxes in the grid.
  • Infinite scroll that loads more items as you near the bottom.

Where it's asked

  • Amazon · Technical phone screen · Last asked Jan 202660 min · Live coding in a shared editor that does not run code, plus Leadership Principles questions · No AI

What it tests

frontend · css · layout

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding