Suggest Study Partners
Problem
A study app logs which practice problems each student solved on each day, and tracks existing study-partner links.
DataFrame `solved` (from `solved.csv`):
```text
+------------+------+
| Column | Type |
+------------+------+
| student_id | int |
| problem_id | int |
| solve_date | date |
+------------+------+
Each row means the student solved the problem on the given date.
```
DataFrame `partners` (from `partners.csv`):
```text
+-----------+------+
| Column | Type |
+-----------+------+
| student_x | int |
| student_y | int |
+-----------+------+
(student_x, student_y) is the primary key. Each row means the two students are already study partners.
```
Suggest student `a` to student `b` when both hold:
- `a` and `b` are not already study partners (in either direction).
- `a` and `b` solved the same **three or more distinct problems on the same day**.
Suggestions are bidirectional: if `a` is suggested to `b`, then `b` must also be suggested to `a`. The result must contain no duplicate rows.
Return a DataFrame with columns `student_id` and `suggested_id`, in any order.
Input data
Example rows — the live problem includes the full dataset.
| student_id | problem_id | solve_date |
|---|---|---|
| 1 | 10 | 2021-03-15 |
| 1 | 11 | 2021-03-15 |
| 1 | 12 | 2021-03-15 |
| 2 | 10 | 2021-03-15 |
| 2 | 11 | 2021-03-15 |
| student_x | student_y |
|---|---|
| 1 | 2 |
Expected output
Your answer should return 6 rows with the columns student_id, suggested_id.
Starter code (Pandas (Python))
import pandas as pd
def suggest_study_partners(solved, partners) -> pd.DataFrame:
# Your code here
return solvedSolve this Pandas question free
Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock