EasyNo. 0620

Not Boring Movies — LeetCode 620 Python Solution

Topics
Database
Reading time
2 min

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

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

PythonSolution
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

Related problems
No.ProblemDifficulty
0619Biggest Single NumberEasy
0626Exchange SeatsMedium
0627Swap Sex of EmployeesEasy
0610Triangle JudgementEasy
0175Combine Two TablesEasy
0176Second Highest SalaryMedium

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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.