Accepted Candidates From the Interviews — LeetCode 2041 Python Solution

MediumLeetCode PremiumDatabase
Problem
#2041
Reading time
2 min

Table schema

SQL
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

SQL
+--------------+----------+
| 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

Python
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

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

Related problems

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.

Get Stealth Interview