EasyNo. 0620
Not Boring Movies — LeetCode 620 Python Solution
- Topics
- Database
- 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
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
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0619 | Biggest Single Number | Easy |
| 0626 | Exchange Seats | Medium |
| 0627 | Swap Sex of Employees | Easy |
| 0610 | Triangle Judgement | Easy |
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
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.