HardNo. 1412LeetCode Premium
Find the Quiet Students in All Exams — LeetCode 1412 Python Solution
- Topics
- Database
- Reading time
- 5 min
- Source
- leetcode.com
Table schema
Table: Student +---------------------+---------+ | Column Name | Type | +---------------------+---------+ | student_id | int | | student_name | varchar | +---------------------+---------+ student_id is the primary key (column with unique values) for this table. student_name is the name of the student.Example
+---------------------+---------+
| Column Name | Type |
+---------------------+---------+
| student_id | int |
| student_name | varchar |
+---------------------+---------+
student_id is the primary key (column with unique values) for this table.
student_name is the name of the student.Python solution
import duckdb
import pandas as pd
def solution(student: pd.DataFrame, exam: pd.DataFrame) -> pd.DataFrame:
con = duckdb.connect()
con.register("Student", student)
con.register("Exam", exam)
return con.execute("""WITH
T AS (
SELECT
student_id,
RANK() OVER (
PARTITION BY exam_id
ORDER BY score
) AS rk1,
RANK() OVER (
PARTITION BY exam_id
ORDER BY score DESC
) AS rk2
FROM Exam
)
SELECT student_id, student_name
FROM
T
JOIN Student USING (student_id)
GROUP BY 1
HAVING SUM(rk1 = 1) = 0 AND SUM(rk2 = 1) = 0
ORDER BY 1;""").df()Complexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 1412. Find the Quiet Students in All Exams?
LeetCode 1412. Find the Quiet Students in All Exams is rated Hard on LeetCode.
- What topics does LeetCode 1412. Find the Quiet Students in All Exams cover?
LeetCode 1412. Find the Quiet Students in All Exams is tagged Database on LeetCode.
- Is LeetCode 1412. Find the Quiet Students in All Exams a premium problem?
Yes. LeetCode 1412. Find the Quiet Students in All Exams is a LeetCode Premium problem, so the full statement and test cases require a paid LeetCode subscription.