Code RoomSection header scroll
EasyPrep Room Coding #4768

Section header scroll

CodingAlgorithms & data structuresEntry–Mid~14 min

A virtualised contacts list groups people into alphabet sections, and each section pins its own header to the top of the window while any of its rows are in view. Every row takes the same pixel height, and a header floats above its rows rather than occupying one. sizes gives the row count of each section in display order, and a section is allowed to hold zero rows. A section therefore covers a pixel band that begins where the sections before it end and runs for its own rows, with the pixel one past the band belonging to whatever follows. For each scroll position given, return the index of the section whose band holds that position, or -1 once the position sits at or beyond the end of the content. A section with no rows can never be pinned. Positions are never negative and arrive in any order.

Implement
sticky_section_index(row_height: int, sizes: list[int], offsets: list[int]) → list[int]
Examples
in[20,[3,2,4],[0,59,60,180,200]]out[0,0,1,-1,-1]
in[10,[2,0,1],[19,20,25,30]]out[0,2,2,-1]
in[40,[2,3],[200,79,0,80,119]]out[-1,0,0,1,1]
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 14 min
InputExpectedGot
[20,[3,2,4],[0,59,60,180,200]][0,0,1,-1,-1]not run yetsample
[10,[2,0,1],[19,20,25,30]][0,2,2,-1]not run yetsample
[40,[2,3],[200,79,0,80,119]][-1,0,0,1,1]not run yetsample