Simple solution beats 99.9%
Intuition\nThe task requires us to find pairs of actor_id and director_id who have collaborated at least three times. The initial thought is to group the data b
# Intuition\nThe task requires us to find pairs of `actor_id` and `director_id` who have collaborated at least three times. The initial thought is to group the data by each unique actor-director pair and then filter out the pairs that meet the collaboration threshold.\n\n# Approach\n1. **GROUP BY**: Use `GROUP BY actor_id, director_id` to aggregate rows for each actor-director pair.\n2. **COUNT & HAVING**: We use `COUNT(timestamp)` to determine the number of collaborations for each pair, and `HAVING COUNT(timestamp) >= 3` to retain only those pairs with at least three collaborations.\n\nThis approach is efficient, leveraging SQL\'s aggregation and filtering capabilities to retrieve the required data.\n\n# Complexity\n- **Time complexity**: $$O(n)$$, where $$n$$ is the number of rows in the `ActorDirector` table. The grouping and counting operations depend linearly on the size of the input.\n- **Space complexity**: $$O(k)$$, where $$k$$ is the number of unique actor-director pairs, as the grouping requires storage for each unique pair.\n\n# Code\n```mysql []\n# Write your MySQL query statement below\nSELECT actor_id, director_id\nFROM ActorDirector\nGROUP BY actor_id, director_id\nHAVING COUNT(timestamp) >= 3;\n```
['Database', 'MySQL']