Students With Invalid Departments — LeetCode 1350 Python Solution
EasyLeetCode PremiumDatabase
- Problem
- #1350
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
Table: Departments +---------------+---------+ | Column Name | Type | +---------------+---------+ | id | int | | name | varchar | +---------------+---------+ In SQL, id is the primary key of this table. The table has information about the id of each department of a university.Example
SQL
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| name | varchar |
+---------------+---------+
In SQL, id is the primary key of this table.
The table has information about the id of each department of a university.Python solution
Python
import duckdb
import pandas as pd
def solution(departments: pd.DataFrame, students: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Departments", departments)
con.register("Students", students)
return con.execute("""SELECT id, name
FROM Students
WHERE department_id NOT IN (SELECT id FROM Departments);""").df()Complexity
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 1350. Students With Invalid Departments?
- LeetCode 1350. Students With Invalid Departments is rated Easy on LeetCode.
- What topics does LeetCode 1350. Students With Invalid Departments cover?
- LeetCode 1350. Students With Invalid Departments is tagged Database on LeetCode.
- Is LeetCode 1350. Students With Invalid Departments a premium problem?
- Yes. LeetCode 1350. Students With Invalid Departments is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.