Code RoomRecycled table rows
EasyPrep Room Coding #4719

Recycled table rows

CodingAlgorithms & data structuresEntry–Mid~15 min

A virtualised table recycles row components as the user scrolls, and you are measuring how much work that costs. Every row is the same pixel height, so row i covers the band starting at i times that height and ending just before the next multiple. The table holds total_rows rows and the window shows viewport pixels at once. At a given scroll offset the table keeps exactly the rows whose band overlaps the visible band, limited to the rows that exist. You receive the scroll offsets the user produced, in time order. For each offset report how many of its rows were not present at the offset before it, counting every row for the first offset. Offsets are never negative, and both the row height and the viewport are at least 1. Return one count per offset, in the same order.

Implement
row_mount_churn(row_height: int, viewport: int, total_rows: int, offsets: list[int]) → list[int]
Examples
in[50,200,100,[0,50,400]]out[4,1,4]
in[40,100,10,[0,0,20]]out[3,0,0]
in[30,90,5,[200]]out[0]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 15 min
InputExpectedGot
[50,200,100,[0,50,400]][4,1,4]not run yetsample
[40,100,10,[0,0,20]][3,0,0]not run yetsample
[30,90,5,[200]][0]not run yetsample