Hone logo
Hone
Problems

Actors and Directors Who Cooperated At Least Three Times

This challenge explores relationships within a film database. You'll be given data representing actors and directors, along with the films they've worked on together. The goal is to identify pairs of actors and directors who have collaborated on at least three separate films.

Problem Description

You are provided with a dataset representing film collaborations. This dataset consists of a list of films, where each film has an associated actor and director. Your task is to identify all pairs of actors and directors who have collaborated on three or more films. The output should be a list of tuples, where each tuple contains an actor's name and a director's name, representing a collaboration that meets the minimum threshold.

Key Requirements:

  • Collaboration Count: A collaboration is counted when an actor and director appear together on a film.
  • Minimum Collaborations: Only actor-director pairs with three or more collaborations should be included in the output.
  • Unordered Pairs: The order of the actor and director within a tuple does not matter (e.g., ("ActorA", "DirectorB") is the same as ("DirectorB", "ActorA")).
  • Unique Pairs: Each actor-director pair should only appear once in the output, regardless of how many films they've collaborated on beyond the minimum.

Expected Behavior:

The function should take a list of film records as input and return a list of tuples representing the actor-director pairs who have collaborated on at least three films. If no such pairs exist, an empty list should be returned.

Edge Cases to Consider:

  • Empty Input: What should happen if the input list is empty?
  • Fewer Than Three Films: What if there are fewer than three films in the dataset?
  • Duplicate Films: How should duplicate film entries (same actor and director) be handled? They should be counted as separate collaborations.
  • Same Actor/Director on Multiple Films with Different Partners: An actor or director appearing on many films with different partners should not affect the result. Only collaborations with the same director/actor are counted.

Examples

Example 1:

Input: [("Film1", "ActorA", "DirectorX"), ("Film2", "ActorA", "DirectorX"), ("Film3", "ActorA", "DirectorX"), ("Film4", "ActorB", "DirectorY"), ("Film5", "ActorA", "DirectorZ")]
Output: [("ActorA", "DirectorX")]
Explanation: ActorA and DirectorX collaborated on three films ("Film1", "Film2", "Film3"). ActorA and DirectorZ collaborated only once. ActorB and DirectorY collaborated only once.

Example 2:

Input: [("Film1", "ActorA", "DirectorX"), ("Film2", "ActorA", "DirectorX"), ("Film3", "ActorA", "DirectorY"), ("Film4", "ActorB", "DirectorY"), ("Film5", "ActorC", "DirectorZ")]
Output: []
Explanation: ActorA and DirectorX collaborated on two films. ActorA and DirectorY collaborated on one film. ActorB and DirectorY collaborated on one film. No pair collaborated on at least three films.

Example 3: (Edge Case - Empty Input)

Input: []
Output: []
Explanation:  An empty input list results in an empty output list.

Constraints

  • Input Size: The input list can contain up to 1000 film records.
  • String Length: Actor and director names are strings with a maximum length of 50 characters. Film titles have a maximum length of 100 characters.
  • Performance: The solution should ideally run in O(n) time, where n is the number of film records. While not strictly enforced, solutions with significantly worse performance may be considered less optimal.
  • Input Format: The input is a list of tuples, where each tuple represents a film and contains (film_title, actor_name, director_name).

Notes

Consider using a dictionary or hash map to efficiently count the collaborations between actors and directors. Think about how to group collaborations by actor and director to easily determine if the minimum threshold is met. The problem emphasizes efficiency, so avoid nested loops where possible. Focus on creating a clear and readable solution.

Loading editor...
plaintext