MediumNo. 2041LeetCode Premium

Accepted Candidates From the Interviews — LeetCode 2041 Python Solution

Topics
Database
Reading time
2 min

Table schema

SQLTable schema
Table: Candidates +--------------+----------+ | Column Name | Type | +--------------+----------+ | candidate_id | int | | name | varchar | | years_of_exp | int | | interview_id | int | +--------------+----------+ candidate_id is the primary key (column with unique values) for this table. Each row of this table indicates the name of a candidate, their number of years of experience, and their interview ID.

Example

SQLExample
+--------------+----------+
| Column Name  | Type     |
+--------------+----------+
| candidate_id | int      |
| name         | varchar  |
| years_of_exp | int      |
| interview_id | int      |
+--------------+----------+
candidate_id is the primary key (column with unique values) for this table.
Each row of this table indicates the name of a candidate, their number of years of experience, and their interview ID.

Python solution

PythonSolution
import pandas as pd


def accepted_candidates(candidates: pd.DataFrame, rounds: pd.DataFrame) -> pd.DataFrame:
    merged_df = pd.merge(candidates, rounds, on="interview_id")
    filtered_df = merged_df[merged_df["years_of_exp"] >= 2]
    grouped_df = filtered_df.groupby("candidate_id").agg({"score": "sum"})
    return grouped_df[grouped_df["score"] > 15].reset_index()[["candidate_id"]]

Complexity

Time
O(n log n)(typical)
Space · auxiliary
O(n)

Related problems

Related problems
No.ProblemDifficulty
0175Combine Two TablesEasy
0176Second Highest SalaryMedium
0177Nth Highest SalaryMedium
0178Rank ScoresMedium
0180Consecutive NumbersMedium
0181Employees Earning More Than Their ManagersEasy

Frequently asked questions

How hard is LeetCode 2041. Accepted Candidates From the Interviews?

LeetCode 2041. Accepted Candidates From the Interviews is rated Medium on LeetCode.

What topics does LeetCode 2041. Accepted Candidates From the Interviews cover?

LeetCode 2041. Accepted Candidates From the Interviews is tagged Database on LeetCode.

Is LeetCode 2041. Accepted Candidates From the Interviews a premium problem?

Yes. LeetCode 2041. Accepted Candidates From the Interviews 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.

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