Not Boring Movies — LeetCode 620 Python Solution
EasyDatabase
- Problem
- #620
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Report the movies whose id is odd and whose description is not "boring", ordered by rating from highest to lowest. The Cinema table has one row per movie: id (int, the primary key), movie (varchar, the title), description (varchar, the genre) and rating (float with two decimals, between 0 and 10).
Example
Cinema table: | id | movie | description | rating | | -- | --------- | ----------- | ------ | | 1 | Skyfall | thrilling | 8.6 | | 2 | Dust | boring | 6.2 | | 3 | Longshot | boring | 5.4 | | 4 | Harbor | touching | 7.9 | | 5 | Nightfall | gripping | 9.1 | Result: | id | movie | description | rating | | -- | --------- | ----------- | ------ | | 5 | Nightfall | gripping | 9.1 | | 1 | Skyfall | thrilling | 8.6 | Of the odd ids 1, 3 and 5, only 3 is boring and drops out, and the two survivors come back best rating first.
Python solution
Python
import pandas as pd
def not_boring_movies(cinema: pd.DataFrame) -> pd.DataFrame:
res = cinema[(cinema['id'] % 2 == 1) & (cinema['description'] != 'boring')]
return res[['id', 'movie', 'description', 'rating']].sort_values('rating', ascending=False)Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 620. Not Boring Movies?
- LeetCode 620. Not Boring Movies is rated Easy on LeetCode.
- What topics does LeetCode 620. Not Boring Movies cover?
- LeetCode 620. Not Boring Movies is tagged Database on LeetCode.