The first screen is the first few slots of every row
The data is a list of lists. Row 0 is the top of the page, and inside a row, position 0 is the best title, the one the ranking put first. The screen shows a fixed number of slots from the left of each row. The viewer sees the rest of a row only after scrolling it sideways.
So the screen is a slice of every row:
PAGE = [["A", "B", "C"], ["B", "A", "D", "E"], ["C", "F", "A"]]
print([row[:2] for row in PAGE])
[['A', 'B'], ['B', 'A'], ['C', 'F']]
Here it is as a grid, with the two slots on the screen in the left panel. A and B each appear twice on the screen. That is the problem in one picture.
on the screen past the screen Row 1 repeats B and A from row 0. The C in row 2 is fine: row 0's C is past the screen.
Two facts follow, and the whole problem rests on them:
- A title past the screen is not on the screen. Row 0's C doesn't stop row 2 from showing C.
- A short row shows what it has.
row[:width]never fails, it just returns fewer titles.
The first thing to write is the checker, before any fix: which titles does the screen show more than once? A Counter over the screen's titles answers it.
In the editor, write screen(rows, width), the screen as a list of slices, and screen_repeats(rows, width), the titles it shows twice or more, sorted.