1341. Movie Rating LeetCode Solution

In this guide, you will get 1341. Movie Rating LeetCode Solution with the best time and space complexity. The solution to Movie Rating problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.

Table of Contents

  1. Problem Statement
  2. Complexity Analysis
  3. Movie Rating solution in C++
  4. Movie Rating solution in Java
  5. Movie Rating solution in Python
  6. Additional Resources
1341. Movie Rating LeetCode Solution image

Problem Statement of Movie Rating

Table: Movies

+—————+———+
| Column Name | Type |
+—————+———+
| movie_id | int |
| title | varchar |
+—————+———+
movie_id is the primary key (column with unique values) for this table.
title is the name of the movie.

Table: Users

+—————+———+
| Column Name | Type |
+—————+———+
| user_id | int |
| name | varchar |
+—————+———+
user_id is the primary key (column with unique values) for this table.
The column ‘name’ has unique values.

Table: MovieRating

+—————+———+
| Column Name | Type |
+—————+———+
| movie_id | int |
| user_id | int |
| rating | int |
| created_at | date |
+—————+———+
(movie_id, user_id) is the primary key (column with unique values) for this table.
This table contains the rating of a movie by a user in their review.
created_at is the user’s review date.

Write a solution to:

Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.
Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.

The result format is in the following example.

Example not found

Constraints not found

Complexity Analysis

  • Time Complexity: Google AdSense
  • Space Complexity: Google Analytics

1341. Movie Rating LeetCode Solution in C++

(
  SELECT Users.name AS results
  FROM MovieRating
  INNER JOIN Users
    USING (user_id)
  GROUP BY user_id
  ORDER BY COUNT(MovieRating.movie_id) DESC, Users.name
  LIMIT 1
)
UNION ALL
(
  SELECT Movies.title AS results
  FROM MovieRating
  INNER JOIN Movies
    USING (movie_id)
  WHERE DATE_FORMAT(created_at, '%Y-%m') = '2020-02'
  GROUP BY movie_id
  ORDER BY AVG(MovieRating.rating) DESC, Movies.title
  LIMIT 1
);
/* code provided by PROGIEZ */

1341. Movie Rating LeetCode Solution in Java

N/A
// code provided by PROGIEZ

1341. Movie Rating LeetCode Solution in Python

N/A
# code by PROGIEZ

Additional Resources

Happy Coding! Keep following PROGIEZ for more updates and solutions.