Viewers With Matching Recent Watches

Asked at NetflixPhone screen

Reported by the problem's creator, not verified

You are given a ViewingHistory class built from histories, a dictionary mapping each user id to that user's watch history: movie ids in the order the user watched them, oldest first. A movie may appear more than once in one history.

A user's recent movies for k are the distinct movies among the last k entries of their history. A shorter history uses all its entries, and an empty history gives the empty set. Order and repeats do not matter.

Histories never change after construction.

Examples

  1. Example 1

    Input: init = [{"cy":[2,4,3,7],"ann":[1,2,3,4],"bob":[9,3,4,2],"dee":[5,6],"eve":[6,5],"fay":[4,4,3,2],"gus":[8]}], operations = [["groups",[3]],["groups",[2]],["groups",[1]],["groups",[10]]]

    Output: [[["ann","bob","fay"],["dee","eve"]],[["dee","eve"]],[["bob","fay"]],[["dee","eve"]]]

    Explanation: With k = 3, ann, bob and fay all have the recent set {2, 3, 4} despite different orders and a repeat, and dee and eve both have {5, 6}; gus matches nobody. For k = 2 only dee and eve still match, for k = 1 only bob and fay share the movie 2, and for k = 10 the full histories again match only dee and eve.

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.