Friendly Movies Streamed Last Month — LeetCode 1495 Python Solution

EasyLeetCode PremiumDatabase
Problem
#1495
Reading time
3 min

Table schema

SQL
Table: TVProgram +---------------+---------+ | Column Name | Type | +---------------+---------+ | program_date | date | | content_id | int | | channel | varchar | +---------------+---------+ (program_date, content_id) is the primary key (combination of columns with unique values) for this table. This table contains information of the programs on the TV.

Example

SQL
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| program_date  | date    |
| content_id    | int     |
| channel       | varchar |
+---------------+---------+
(program_date, content_id) is the primary key (combination of columns with unique values) for this table.
This table contains information of the programs on the TV.
content_id is the id of the program in some channel on the TV.

Python solution

Python
import duckdb
import pandas as pd

def solution(tvprogram: pd.DataFrame, content: pd.DataFrame) -> pd.DataFrame:
    con = duckdb.connect()
    con.register("TVProgram", tvprogram)
    con.register("Content", content)
    return con.execute("""SELECT DISTINCT title
FROM
    TVProgram
    JOIN Content USING (content_id)
WHERE
    DATE_FORMAT(program_date, '%Y%m') = '202006'
    AND kids_content = 'Y'
    AND content_type = 'Movies';""").df()

Complexity

MeasureComplexity
TimeO(n log n) (typical)
SpaceO(n) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 1495. Friendly Movies Streamed Last Month?
LeetCode 1495. Friendly Movies Streamed Last Month is rated Easy on LeetCode.
What topics does LeetCode 1495. Friendly Movies Streamed Last Month cover?
LeetCode 1495. Friendly Movies Streamed Last Month is tagged Database on LeetCode.
Is LeetCode 1495. Friendly Movies Streamed Last Month a premium problem?
Yes. LeetCode 1495. Friendly Movies Streamed Last Month is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.

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.

Get Stealth Interview