AnalystPath

Suggest Study Partners

SQLHardSenior level~15 min

Problem

A study app logs which practice problems each student solved on each day, and tracks existing study-partner links.

Table: solved

| Column Name | Type |
|-------------|------|
| student_id | int |
| problem_id | int |
| solve_date | date |

Each row means the student solved the problem on the given date.

Table: partners

| Column Name | Type |
|-------------|------|
| student_x | int |
| student_y | int |

(student_x, student_y) is the primary key for this table. Each row means student_x and student_y are already study partners.

Suggest student a to student b when both of the following 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 student_id and suggested_id in any order.

Tables

Example rows — the live problem includes the full dataset.

solved
student_idproblem_idsolve_date
1102021-03-15
1112021-03-15
1122021-03-15
partners
student_xstudent_y
12

Expected output

Your answer should return 6 rows with the columns student_id, suggested_id.

Starter code (SQL)

SELECT *
FROM solved;

Solve this SQL question free

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

Related SQL questions