← 返回 netflix 的题目列表Group Users by Movie Viewing History
类型:online_judge
Given a list of users with their movie viewing history, group users who have the same set of the last k movies viewed. Each element in the list represents a user and their history of movies, sorted by view time from oldest to newest.
Input:
users: A two-dimensional array containing users' movie history, formatted as [['user1', MovieID1, MovieID2, ...], ['user2', MovieID3, MovieID4, ...], ...]
k: An integer representing the number of recent movies to consider
Output:
A list of user groups having the same set of last k movies, with users in each group sorted lexicographically.
Test case:
Input: users = [['user1', 1, 2, 3], ['user2', 3, 1, 2], ['user3', 1, 2, 3]], k = 2
Output: [('user1', 'user3'), ('user2',)]
Example
Input
['user1', 1, 2, 3]
['user2', 3, 1, 2]
['user3', 1, 2, 3]
2