← 返回 netflix 的题目列表Dedupe Titles in Viewport
类型:online_judge
The Netflix home page has a list of shelves, each containing a number of titles. We want to deduplicate these titles in the viewport (each shelf can display a maximum of X unique titles). Vertical scrolling can be ignored.
Implement a function to deduplicate these titles:
def dedupe_v5(titles: list[list[int]], x: int) -> list[list[int]]:
This function should return a list where each element is a potentially deduplicated list.
Parameters:
titles: A list where each element is a list of titles on a shelf. Titles are represented by integers.
x: Maximum number of unique titles that can be displayed in the viewport per shelf.
Example:
>>> dedupe_v5([[1, 2, 2, 3, 4], [1, 2, 5, 6, 4]], 3)
[[1, 2, 3, 4], [5, 6, 4]]
>>> dedupe_v5([[5, 5, 1, 2], [1, 1, 1, 2, 3]], 1)
[[5], [1, 2, 3]]
Constraints:
1 <= x <= 100
1 <= titles[i].length <= 100
1 <= titles[i][j] <= 1000
Example
Input
[[1, 2, 2, 3, 4], [1, 2, 5, 6, 4]] 3
Output
[[1, 2, 3, 4], [5, 6, 4]]