Loading content...
An academic analytics team wants to identify students who are excelling within their own major track.
You are given three tables:
Students
Courses
Enrollments
Task: Return students who satisfy all of the following conditions.
Mandatory-major completion with A grade: For every mandatory course in the student's own major, the student must have at least one enrollment attempt with grade "A".
Elective-major breadth with strong grades: The student must have at least two distinct elective courses in their own major where at least one enrollment attempt has grade "A" or "B".
Overall GPA floor: The student's average GPA across all enrollment rows (including courses outside their major) must be at least 2.5.
Output requirements:
Supported submission environments:
Students:
| student_id | name | major |
|------------|---------|-------------------|
| 1 | Alice | Computer Science |
| 2 | Bob | Computer Science |
| 3 | Charlie | Mathematics |
| 4 | David | Mathematics |
Courses:
| course_id | name | credits | major | mandatory |
|-----------|-------------------|---------|------------------|-----------|
| 101 | Algorithms | 3 | Computer Science | Yes |
| 102 | Data Structures | 3 | Computer Science | Yes |
| 103 | Operating Systems | 3 | Computer Science | No |
| 104 | Machine Learning | 3 | Computer Science | No |
| 201 | Calculus | 4 | Mathematics | Yes |
| 202 | Linear Algebra | 4 | Mathematics | Yes |
| 203 | Probability | 3 | Mathematics | No |
| 204 | Statistics | 3 | Mathematics | No |
Enrollments:
| student_id | course_id | semester | grade | gpa |
|------------|-----------|--------------|-------|-----|
| 1 | 101 | Fall 2024 | A | 4.0 |
| 1 | 102 | Spring 2025 | A | 4.0 |
| 1 | 103 | Spring 2025 | A | 4.0 |
| 1 | 104 | Fall 2025 | B | 3.2 |
| 2 | 101 | Fall 2024 | A | 4.0 |
| 2 | 102 | Spring 2025 | B | 3.2 |
| 2 | 103 | Fall 2025 | A | 4.0 |
| 2 | 104 | Fall 2025 | A | 4.0 |
| 3 | 201 | Fall 2024 | A | 4.0 |
| 3 | 202 | Spring 2025 | A | 4.0 |
| 3 | 203 | Spring 2025 | B | 3.2 |
| 3 | 204 | Fall 2025 | A | 4.0 |
| 4 | 201 | Fall 2024 | A | 4.0 |
| 4 | 202 | Spring 2025 | A | 4.0 |
| 4 | 203 | Spring 2025 | C | 2.1 |[
{"student_id": 1},
{"student_id": 3}
]Student 1 and 3 satisfy all three rules. Student 2 fails mandatory-grade-A coverage, and student 4 does not have two elective courses with grade A/B.
Students:
| student_id | name | major |
|------------|------|---------|
| 9 | Isha | Finance |
Courses:
| course_id | name | credits | major | mandatory |
|-----------|-------------|---------|---------|-----------|
| 510 | Accounting | 3 | Finance | Yes |
| 511 | Markets | 3 | Finance | Yes |
| 512 | Derivatives | 3 | Finance | No |
| 513 | Valuation | 3 | Finance | No |
Enrollments:
| student_id | course_id | semester | grade | gpa |
|------------|-----------|--------------|-------|-----|
| 9 | 510 | Fall 2024 | C | 2.1 |
| 9 | 510 | Spring 2025 | A | 4.0 |
| 9 | 511 | Spring 2025 | A | 4.0 |
| 9 | 512 | Spring 2025 | B | 3.2 |
| 9 | 513 | Fall 2025 | A | 4.0 |[
{"student_id": 9}
]Retakes are allowed in this formulation. Course 510 has at least one A attempt, and both electives are satisfied with A/B grades.
Students:
| student_id | name | major |
|------------|-------|-------|
| 20 | Nora | Stats |
Courses:
| course_id | name | credits | major | mandatory |
|-----------|--------------------|---------|-------|-----------|
| 701 | Core Inference | 4 | Stats | Yes |
| 702 | Core Modeling | 4 | Stats | Yes |
| 703 | Elective A | 3 | Stats | No |
| 704 | Elective B | 3 | Stats | No |
Enrollments:
| student_id | course_id | semester | grade | gpa |
|------------|-----------|--------------|-------|-----|
| 20 | 701 | Fall 2024 | A | 4.0 |
| 20 | 702 | Spring 2025 | A | 4.0 |
| 20 | 703 | Spring 2025 | A | 4.0 |
| 20 | 704 | Fall 2025 | B | 2.0 |[
{"student_id": 20}
]Average GPA is exactly 2.5, which passes the threshold.
Constraints