What interviewers ask next
The reports name two follow-ups, and the practice problem turns both into levels: a different n for each row, and rows that skip the dedup (1 report). The rest of this part covers questions that follow naturally from the design. They are not from the reports, but each one tests whether you understood the pieces.
- What does the dedup cost the ranking? Every title pulled onto the screen from deeper in a row is a worse pick than the ranker wanted. Measure it.
- What if rows load as the viewer scrolls down? Then there is no list of rows, only one row at a time, and
shownhas to live between calls. - What if every slot should be filled? That is the fill-first choice from part 4, and greedy can't do it.
- What tests would you write? One candidate had to write their own test cases after the code (1 report).
Start with the cost to the ranking. For each slot j on the screen, the title came from its first position in the row. The gap between the two is how far the dedup pulled it up:
row, placed = ["B", "A", "D", "E"], ["D", "E", "B", "A"]
first = {}
for i, title in enumerate(row):
first.setdefault(title, i)
print([first[t] - j for j, t in enumerate(placed[:2])])
[2, 2]
D moved from 2 to 0 and E from 3 to 1, 4 places in all. Summed over a page and averaged over many viewers, this is the number to watch when someone wants a stricter rule. A big jump means the rows are too alike, and the fix belongs in the rankers, not the dedup.
In the editor, write pulled_up(row, placed, width): the sum, over the slots on the screen, of how far each title came from.