Dedupe Homepage Shelves

Asked at Netflix· Screen

Reported by the problem's creator, not verified

Import another question

A streaming home page shows shelves from top to bottom, and each shelf is an ordered list of title ids. Implement dedupe_shelves(shelves, viewport), which returns the cleaned shelves in the same order, keeping the surviving titles of each shelf in their original relative order.

Within every shelf a title appears at most once: a later copy of a title already in that same shelf is dropped.

Examples

  1. Example 1

    Input: shelves = [[1,2,3],[2,4,3],[3,5,6]], viewport = 2

    Output: [[1,2,3],[4,3],[3,5,6]]

    Explanation: Shelf 0's window keeps and marks 1 and 2. In shelf 1 the window is positions 0 and 1: 2 is already marked, so it is dropped, and 4 is kept. Title 3 sits at position 2, outside the window, so shelf 1 keeps it. Shelf 2's window starts with 3, which no earlier window kept, so shelf 2 is unchanged.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.