Bloomberg | Online | Measure TV Show Addictiveness
Anonymous User
1575

Measure TV Show Addictiveness

Problem Statement:

One way to measure how "addictive" a TV show is to look at the number of viewers who finish a show after watching a certain number of episodes. We want to find the nth episode such that 70% of the viewers of the nth episode will continue to watch all episodes of the show. The lower the value of n, the more addictive the show is.

We can assume that all shows have 10 episodes and all viewers watch the episodes sequentially without skipping. Given a log of entries consisting of:

  • user_id: an integer representing the viewer's ID.
  • show_name: a string representing the name of the show.
  • episode_number: an integer representing the episode number the user watched.

You need to find n for each show.

You can assume this function is called for each log entry.

Function Signature:

void process_log(string show, int episode, int user_id);
void print_results();

Input:
The process_log(string show, int episode, int user_id) function is called for each log entry to process the viewing data.
After processing all log entries, the print_results() function is called to calculate and print the results.

Output:
The print_results() function should output the earliest episode n for each show where at least 70% of viewers continue watching until the last episode. If no such episode n is found for a show, it should indicate this.

Example usage

int main() {
    process_log("Breaking Bad", 1, 1001);
    process_log("Breaking Bad", 2, 1001);
    process_log("Breaking Bad", 3, 1001);
    process_log("Breaking Bad", 10, 1001);
    process_log("Breaking Bad", 1, 1002);
    process_log("Breaking Bad", 2, 1002);
    process_log("Breaking Bad", 1, 1003);
    process_log("Breaking Bad", 2, 1003);
    process_log("Breaking Bad", 3, 1003);
    process_log("Breaking Bad", 4, 1003);
    process_log("Breaking Bad", 5, 1003);
    process_log("Breaking Bad", 6, 1003);
    process_log("Breaking Bad", 7, 1003);
    process_log("Breaking Bad", 8, 1003);
    process_log("Breaking Bad", 9, 1003);
    process_log("Breaking Bad", 10, 1003);

    process_log("Game of Thrones", 1, 2001);
    process_log("Game of Thrones", 2, 2001);
    process_log("Game of Thrones", 3, 2001);
    process_log("Game of Thrones", 4, 2001);
    process_log("Game of Thrones", 5, 2001);
    process_log("Game of Thrones", 1, 2002);
    process_log("Game of Thrones", 2, 2002);
    process_log("Game of Thrones", 3, 2002);
    process_log("Game of Thrones", 4, 2002);
    process_log("Game of Thrones", 5, 2002);
    process_log("Game of Thrones", 6, 2002);
    process_log("Game of Thrones", 7, 2002);
    process_log("Game of Thrones", 8, 2002);
    process_log("Game of Thrones", 9, 2002);
    process_log("Game of Thrones", 10, 2002);

    print_results();

    return 0;
}

Constraints:

  • show_name consists of lowercase English letters and spaces.
  • episode_number is an integer between 1 and 10.
  • user_id is an integer.
  • The log size can be up to 100,000 entries.
Comments (3)