Code RoomVirtual column rendering
EasyPrep Room Coding #4796

Virtual column rendering

CodingAlgorithms & data structuresEntry–Mid~15 min

A data grid virtualises its columns as well as its rows. widths gives the pixel width of each column in display order, and the first frozen columns are pinned to the left edge, so they always render and they cover the leftmost pixels of the window. The scrolling columns sit in a strip of their own that starts at pixel 0, and the window shows the part of that strip beginning at scroll_x and running for whatever width the pinned columns left over. A scrolling column renders when it shares at least one pixel with that part, so a column of zero width never renders, and neither does one ending exactly where the part begins. When the pinned columns fill the window on their own, only they render. Return the indices of every rendered column, in ascending order.

Implement
rendered_grid_columns(widths: list[int], frozen: int, viewport: int, scroll_x: int) → list[int]
Examples
in[[120,80,200,90,150],1,300,0]out[0,1,2]
in[[120,80,200,90,150],1,300,100]out[0,2]
in[[60,60,60,60],0,120,60]out[1,2]
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
[[120,80,200,90,150],1,300,0][0,1,2]not run yetsample
[[120,80,200,90,150],1,300,100][0,2]not run yetsample
[[60,60,60,60],0,120,60][1,2]not run yetsample