Problem, as an interviewer would state it: "Given a scroll position and a list of 10,000+ items, compute which small RANGE of item indices actually needs to be rendered — the entire real point being that a real browser genuinely cannot render 10,000 real DOM nodes efficiently."
Examples:
getVisibleRange({ scrollTop: 4000, viewportHeight: 400, itemHeight: 40, totalItems: 10000 });
// { start: 98, end: 112, count: 15 } -- NOT all 10000
Clarifying questions expected:
- Should the range include extra "overscan" items just outside the visible viewport, to reduce flicker during fast scrolling?
- Are all items a fixed, uniform height, or could they genuinely vary?
- Does the container need a real spacer element to maintain correct scrollbar proportions, given only a handful of real DOM nodes actually exist?
Code / implementation expected: Yes — real, direct proof across multiple real scroll positions confirming only a small, bounded window is ever computed as needing to render, never anywhere close to the full item count.