#K38547. User Viewing Analysis
User Viewing Analysis
User Viewing Analysis
You are given data about users' viewing history and the genres of various content pieces. The data is provided in two dictionaries: one mapping each user ID to a list of content IDs they have watched, and another mapping each content ID to its genre.
There are three operations to perform:
- FAVORITE: Determine the favorite genre of a given user. The favorite genre is defined as the genre that appears most frequently in the user's viewing history. In case of ties, choose the genre that appears first in the order of viewing.
- RECOMMEND: Given a genre, recommend a content piece that the user has not watched yet. Among the available content pieces, output the one with the smallest ID.
- COUNT: Count the number of unique genres the user has watched.
For any formulas needed, use LaTeX notation. For example, the count of unique genres is given by \( |\{ g : g \in \text{genres watched} \}| \).
inputFormat
The input is read from standard input (stdin) and has the following format:
OPERATION user_id [If OPERATION is RECOMMEND, then: genre n m]</p>u user_id_1 k1 view1 view2 ... viewk1 user_id_2 k2 view1 view2 ... viewk2 ...
g content_id_1 genre1 content_id_2 genre2 ...
Where:
OPERATION
is one of:FAVORITE
,RECOMMEND
, orCOUNT
.user_id
is the target user's id (an integer).- If
OPERATION
isRECOMMEND
, then the next three tokens are:genre
(a string),n
, andm
(two integers — additional parameters which you may ignore in processing). u
is the number of user view records.- Each user view record consists of a user id, followed by the number of views
k
, thenk
integers representing content IDs. g
is the number of content pieces.- Each content record consists of a content ID and its genre (a string).
outputFormat
The output is written to standard output (stdout) and is as follows:
- For the
FAVORITE
operation, output the favorite genre of the user. If the user has not watched any content, outputNone
. - For the
RECOMMEND
operation, output the content ID (an integer) of the recommended content piece. If no recommendation is available, outputNone
. - For the
COUNT
operation, output an integer representing the number of unique genres the user has watched.
FAVORITE
1
3
1 3 1 2 3
2 2 2 3
3 0
5
1 Action
2 Comedy
3 Drama
4 Action
5 Comedy
Action