Dsa
Hashing
Easy
Unique Movie Combinations
You are tasked with helping a streaming service determine how many unique movie combinations can be formed from a list of movies that share similar genres. Every movie has a unique ID and can belong to multiple genres. Given a list of movie IDs along with their genres, your task is to find out how many unique combinations of movies can be formed that share at least one genre.
Input Format:
- The first line contains an integer N, the number of movies.
- The next N lines contain each movie's details in the format: `movie_id genre1 genre2 ... genreK`, where `movie_id` is a string and `genreX` are the genres associated with the movie (at least one genre is guaranteed).
Output Format:
- Output a single integer representing the count of unique movie combinations that share at least one genre.
Example Input:
4
M1 Action Comedy
M2 Action
M3 Drama
M4 Comedy Drama
Example Output:
5
There are 5 combinations:
- (M1, M2)
- (M1, M4)
- (M2, M4)
- (M3, M4)
- (M1, M3)
Key concepts
hashingcombinationscounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now