72. Frequent Actor-Director Duos

In the film industry, analyzing collaborations between actors and directors can help production houses identify successful pairs. These frequent collaborations may reflect strong creative chemistry and successful outcomes.

You are given a ActorDirector table:

╔═════════════╦══════════╗
ā•‘ Column Name ā•‘   Type   ā•‘
╠═════════════╬══════════╣
ā•‘  actor_id   ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘ director_id ā•‘   int    ā•‘
║─────────────┼──────────║
ā•‘  timestamp  ā•‘   int    ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•
  • actor_id: ID of the actor involved in the collaboration
  • director_id: ID of the director involved in the collaboration
  • timestamp: This ensures that each record is uniquely identified by the time it happened.

Write a query to find all (actor_id, director_id) pairs where the actor has worked with the director three or more times.

Example 1:

Example:

Input:

ActorDirector Table:

╔══════════╦═════════════╦═══════════╗
ā•‘ actor_id ā•‘ director_id ā•‘ timestamp ā•‘
╠══════════╬═════════════╬═══════════╣
ā•‘    1     ā•‘      1      ā•‘     0     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    1     ā•‘      1      ā•‘     1     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    1     ā•‘      1      ā•‘     2     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    1     ā•‘      2      ā•‘     3     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    1     ā•‘      2      ā•‘     4     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    2     ā•‘      1      ā•‘     5     ā•‘
║──────────┼─────────────┼───────────║
ā•‘    2     ā•‘      1      ā•‘     6     ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Output:

╔══════════╦═════════════╗
ā•‘ actor_id ā•‘ director_id ā•‘
╠══════════╬═════════════╣
ā•‘    1     ā•‘      1      ā•‘
ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•©ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•

Explanation:

  • (1, 1) appears 3 times → included.
  • (1, 2) appears 2 times → excluded.
  • (2, 1) appears 2 times → excluded.

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

0
Ā 
Test Case

Input:

ActorDirector