Home
← All questions

Infinite scroll with list virtualization | Frontend Machine Coding

HardPremiumMachine Coding

Frontend Machine Coding interview practice: Build an infinitely scrolling list that fetches more on scroll and virtualizes rendered rows.

Problem

Render a large/endless list efficiently.

Requirements

  • Infinite scroll: fetch the next page when the user nears the bottom.
  • Virtualization (windowing): only render the rows currently visible (plus a small overscan buffer), not the entire list.
  • Maintain correct total scroll height so the scrollbar behaves naturally.

Hints / Approach

  • Infinite scroll: use IntersectionObserver on a sentinel element at the list end, or a scroll listener checking scrollTop + clientHeight >= scrollHeight - threshold.
  • Virtualization (fixed row height): startIndex = floor(scrollTop / rowHeight), visibleCount = ceil(viewportHeight / rowHeight). Render that slice inside a spacer container of height totalRows * rowHeight, offset by startIndex * rowHeight (via transform: translateY or padding).
  • Variable heights: maintain measured offsets / use a library approach (binary search over cumulative heights).
Premium question

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

Unlock with Premium