Hone logo
Hone
Problems

Actors and Directors Who Cooperated At Least Three Times

Given a dataset of movie productions, identify pairs of actors and directors who have collaborated on at least three films together. This challenge tests your ability to process relational data, group information, and apply filtering criteria to extract specific insights. Understanding these frequent collaborations can be valuable for film industry analysis and recommendation systems.

Problem Description

You are provided with a list of movie productions. Each production record contains information about the actors involved and the director of the film. Your task is to find all unique pairs of (actor, director) such that they have worked together on three or more movies.

Key Requirements:

  • Process a list of movie productions, where each production has a director and a list of actors.
  • Count the number of times each unique actor-director pair has collaborated.
  • Return a list of all (actor, director) pairs that have collaborated at least three times.

Expected Behavior:

The output should be a list of pairs, where each pair represents an actor and a director. The order of actors and directors within a pair does not matter (e.g., (Actor A, Director B) is the same as (Director B, Actor A)), but the output should consistently represent each unique pair once. The order of the pairs in the final output list does not matter.

Edge Cases:

  • No collaborations: If no actor-director pair collaborates three or more times, the output should be an empty list.
  • Empty input: If the input list of productions is empty, the output should be an empty list.
  • Movies with no actors or no director: Assume each production will have a director and at least one actor for the purpose of this challenge. However, a robust solution might consider these if they were possible.

Examples

Example 1:

Input:

[
  { "director": "Spielberg", "actors": ["Tom Hanks", "Leonardo DiCaprio"] },
  { "director": "Nolan", "actors": ["Leonardo DiCaprio", "Anne Hathaway"] },
  { "director": "Spielberg", "actors": ["Tom Hanks", "Morgan Freeman"] },
  { "director": "Spielberg", "actors": ["Tom Hanks", "Anne Hathaway"] },
  { "director": "Nolan", "actors": ["Leonardo DiCaprio", "Christian Bale"] }
]

Output:

[ ["Tom Hanks", "Spielberg"] ]

Explanation:

  • "Tom Hanks" and "Spielberg" collaborated 3 times.
  • "Leonardo DiCaprio" and "Spielberg" collaborated 1 time.
  • "Leonardo DiCaprio" and "Nolan" collaborated 2 times.
  • "Anne Hathaway" and "Nolan" collaborated 1 time.
  • "Morgan Freeman" and "Spielberg" collaborated 1 time.
  • "Anne Hathaway" and "Spielberg" collaborated 1 time.
  • "Christian Bale" and "Nolan" collaborated 1 time.

Example 2:

Input:

[
  { "director": "Tarantino", "actors": ["Uma Thurman", "Samuel L. Jackson"] },
  { "director": "Scott", "actors": ["Russell Crowe", "Joaquin Phoenix"] },
  { "director": "Tarantino", "actors": ["Samuel L. Jackson", "Christoph Waltz"] },
  { "director": "Tarantino", "actors": ["Uma Thurman", "Christoph Waltz"] },
  { "director": "Scott", "actors": ["Russell Crowe", "Joaquin Phoenix"] },
  { "director": "Scott", "actors": ["Russell Crowe", "Joaquin Phoenix"] }
]

Output:

[ ["Russell Crowe", "Scott"], ["Joaquin Phoenix", "Scott"] ]

Explanation:

  • "Russell Crowe" and "Scott" collaborated 3 times.
  • "Joaquin Phoenix" and "Scott" collaborated 3 times.
  • "Uma Thurman" and "Tarantino" collaborated 2 times.
  • "Samuel L. Jackson" and "Tarantino" collaborated 2 times.
  • "Christoph Waltz" and "Tarantino" collaborated 2 times.

Example 3: (No collaborations meeting the threshold)

Input:

[
  { "director": "A", "actors": ["X", "Y"] },
  { "director": "B", "actors": ["Y", "Z"] },
  { "director": "A", "actors": ["X", "W"] }
]

Output:

[]

Explanation: No actor-director pair collaborated more than once.

Constraints

  • The number of movie productions will be between 0 and 1000.
  • Each movie production will have a director's name (string) and a list of actor names (list of strings).
  • The length of actor lists can range from 1 to 10.
  • Director and actor names will consist of alphanumeric characters and spaces, and will not be empty strings.
  • Your solution should aim for a time complexity that can efficiently handle the given constraints, ideally better than O(NMA) where N is the number of movies, M is the average number of actors per movie, and A is the number of directors.

Notes

  • Consider how you will store and count the collaborations. A hash map or dictionary is likely a good data structure.
  • Remember to handle the uniqueness of actor-director pairs. The order within a pair should not differentiate it.
  • Think about how to efficiently iterate through the data and aggregate counts.
Loading editor...
plaintext