A virtualized table has count rows, each exactly rowHeight pixels tall. Row i covers pixels from i * rowHeight up to (not including) (i + 1) * rowHeight. The view shows pixels from scrollTop up to (not including) scrollTop + viewportHeight.
Write fixedWindow(count, rowHeight, scrollTop, viewportHeight, overscan) that returns [start, end], the first and last row index to render. A row is visible if it shares at least one pixel with the view. Then extend the range by overscan rows on each side, without going below 0 or past count - 1. If no row is visible, return an empty array.
Input: count = 1000, rowHeight = 40, scrollTop = 130, viewportHeight = 200, overscan = 2 Output: [1,10]
Rows 3 to 8 touch pixels 130 to 329; two extra rows on each side give [1, 10].
Input: count = 5, rowHeight = 50, scrollTop = 0, viewportHeight = 1000, overscan = 1 Output: [0,4]
Everything fits, and the range can't go past the last row.
0 <= count <= 10^91 <= rowHeight, viewportHeight <= 10^40 <= scrollTop <= 10^12, 0 <= overscan <= 50Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #724 Visible Rows with a Fixed Height. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.