Recycled table rows
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.
row_mount_churn(row_height: int, viewport: int, total_rows: int, offsets: list[int]) → list[int][50,200,100,[0,50,400]]out[4,1,4][40,100,10,[0,0,20]]out[3,0,0][30,90,5,[200]]out[0]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.
[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