Skip to content

Practice Find Students Who Improved

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3421
LeetCode Problem

Find Students Who Improved

Problem Statement

Table Scores has student_id INT, subject VARCHAR, score INT, and exam_date VARCHAR containing exam dates. For each student and subject, require exams on at least two dates and a strictly higher latest score than first score. Return student_id, subject, first_score, and latest_score, ordered by student ID then subject ascending. Intermediate decreases do not disqualify an overall first-to-last improvement. Practice approach: Rank each student-subject group by date in both directions, select its first and last scores, and compare them after checking the group has multiple dates. Do not compare maximum and minimum scores, because those may occur in the middle.

Source: Find Students Who Improved on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
{
  "Scores": [
    {
      "student_id": 1,
      "subject": "Math",
      "score": 50,
      "exam_date": "2026-01-01"
    },
    {
      "student_id": 1,
      "subject": "Math",
      "score": 90,
      "exam_date": "2026-02-01"
    },
    {
      "student_id": 1,
      "subject": "Math",
      "score": 60,
      "exam_date": "2026-03-01"
    },
    {
      "student_id": 2,
      "subject": "Math",
      "score": 70,
      "exam_date": "2026-01-01"
    },
    {
      "student_id": 2,
      "subject": "Math",
      "score": 70,
      "exam_date": "2026-02-01"
    },
    {
      "student_id": 3,
      "subject": "Art",
      "score": 95,
      "exam_date": "2026-01-01"
    }
  ]
}
Output
[
  {
    "student_id": 1,
    "subject": "Math",
    "first_score": 50,
    "latest_score": 60
  }
]
Explanation

Student 1 improves from 50 to 60 despite a later decline from 90. Equal scores and a single exam do not qualify.

Constraints

The key is (student_id, subject, exam_date).
Scores range from 0 to 100 inclusive.

Related LeetCode Problems

Practice more problems similar to Find Students Who Improved.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.