Skip to content

Commit 985d8af

Browse files
committed
Update readme.md
1 parent 5ceedac commit 985d8af

File tree

1 file changed

+124
-0
lines changed
  • LeetCode SQL 50 Solution/620. Not Boring Movies

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
Below is a structured README.md snippet for **LeetCode 620: Not Boring Movies**, including the problem statement, example, solution approaches (SQL and Pandas), file structure, and useful links.
2+
3+
---
4+
5+
# **620. Not Boring Movies**
6+
7+
## **Problem Statement**
8+
You are given a table `Cinema` that contains information about movies, their descriptions, and ratings.
9+
10+
### **Cinema Table**
11+
```
12+
+----------------+----------+
13+
| Column Name | Type |
14+
+----------------+----------+
15+
| id | int |
16+
| movie | varchar |
17+
| description | varchar |
18+
| rating | float |
19+
+----------------+----------+
20+
```
21+
- `id` is the **primary key**.
22+
- Each row provides details about a movie:
23+
- `id`: The movie's unique identifier.
24+
- `movie`: The name of the movie.
25+
- `description`: The description or genre of the movie.
26+
- `rating`: A float representing the movie's rating (in the range [0, 10] with 2 decimal places).
27+
28+
### **Task:**
29+
Write a solution to report the movies that have:
30+
- An **odd-numbered `id`**.
31+
- A `description` that is **not "boring"**.
32+
33+
Return the result table **ordered by rating in descending order**.
34+
35+
---
36+
37+
## **Example 1:**
38+
39+
### **Input:**
40+
#### **Cinema Table**
41+
```
42+
+----+------------+-------------+--------+
43+
| id | movie | description | rating |
44+
+----+------------+-------------+--------+
45+
| 1 | War | great 3D | 8.9 |
46+
| 2 | Science | fiction | 8.5 |
47+
| 3 | irish | boring | 6.2 |
48+
| 4 | Ice song | Fantacy | 8.6 |
49+
| 5 | House card | Interesting | 9.1 |
50+
+----+------------+-------------+--------+
51+
```
52+
53+
### **Output:**
54+
```
55+
+----+------------+-------------+--------+
56+
| id | movie | description | rating |
57+
+----+------------+-------------+--------+
58+
| 5 | House card | Interesting | 9.1 |
59+
| 1 | War | great 3D | 8.9 |
60+
+----+------------+-------------+--------+
61+
```
62+
63+
### **Explanation:**
64+
- Movies with **odd-numbered IDs**: `1`, `3`, and `5`.
65+
- Excluding movie with `id = 3` because its description is `"boring"`.
66+
- Sorting the remaining movies by `rating` in descending order gives the result.
67+
68+
---
69+
70+
## **Solution Approaches**
71+
72+
### **SQL Solution**
73+
```sql
74+
SELECT *
75+
FROM Cinema
76+
WHERE id % 2 = 1
77+
AND description != 'boring'
78+
ORDER BY rating DESC;
79+
```
80+
**Explanation:**
81+
- The query filters movies where the `id` is odd (`id % 2 = 1`) and the `description` is not `"boring"`.
82+
- The results are ordered by `rating` in descending order.
83+
84+
---
85+
86+
### **Pandas Solution**
87+
```python
88+
import pandas as pd
89+
90+
def not_boring_movies(cinema: pd.DataFrame) -> pd.DataFrame:
91+
# Filter movies with odd-numbered id and description not equal to 'boring'
92+
result = cinema[(cinema['id'] % 2 == 1) & (cinema['description'] != 'boring')]
93+
# Sort the result by rating in descending order
94+
return result.sort_values(by='rating', ascending=False)
95+
96+
# Example usage:
97+
# cinema_df = pd.read_csv('cinema.csv')
98+
# print(not_boring_movies(cinema_df))
99+
```
100+
**Explanation:**
101+
- The Pandas solution filters the DataFrame to include only rows where the `id` is odd and the `description` is not `"boring"`.
102+
- It then sorts the filtered results by `rating` in descending order.
103+
104+
---
105+
106+
## **File Structure**
107+
```
108+
LeetCode620/
109+
├── problem_statement.md # Contains the problem description and constraints.
110+
├── sql_solution.sql # Contains the SQL solution.
111+
├── pandas_solution.py # Contains the Pandas solution for Python users.
112+
├── README.md # Overview of the problem and available solutions.
113+
```
114+
115+
---
116+
117+
## **Useful Links**
118+
- [LeetCode Problem 620](https://leetcode.com/problems/not-boring-movies/)
119+
- [SQL WHERE Clause Documentation](https://www.w3schools.com/sql/sql_where.asp)
120+
- [Pandas Documentation](https://pandas.pydata.org/docs/)
121+
122+
---
123+
124+
This structured format provides a clear understanding of the problem and offers both SQL and Pandas solutions. Happy coding! 🚀

0 commit comments

Comments
 (0)