Practice Find COVID Recovery Patients
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Tables: patients(patient_id INT, patient_name VARCHAR, age INT) and covid_tests(test_id INT, patient_id INT, test_date DATE, result VARCHAR). This database exercise defines recovery as a Positive test followed on a later date by a Negative test. For each qualifying patient, subtract the first positive date from the first negative date strictly after it. Return patient_id, patient_name, age, and recovery_time in days, sorted by recovery_time then patient_name ascending. Practice approach: Aggregate the earliest positive date first, then find the earliest qualifying later negative. Earlier negative tests and Inconclusive results do not establish recovery. Compute a date difference rather than subtracting day-of-month numbers.
Source: Find COVID Recovery Patients on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
{
"patients": [
{
"patient_id": 1,
"patient_name": "Ava",
"age": 30
},
{
"patient_id": 2,
"patient_name": "Bo",
"age": 40
},
{
"patient_id": 3,
"patient_name": "Cy",
"age": 20
}
],
"covid_tests": [
{
"test_id": 1,
"patient_id": 1,
"test_date": "2026-01-01",
"result": "Negative"
},
{
"test_id": 2,
"patient_id": 1,
"test_date": "2026-01-29",
"result": "Positive"
},
{
"test_id": 3,
"patient_id": 1,
"test_date": "2026-02-02",
"result": "Negative"
},
{
"test_id": 4,
"patient_id": 2,
"test_date": "2026-01-01",
"result": "Positive"
},
{
"test_id": 5,
"patient_id": 2,
"test_date": "2026-01-01",
"result": "Negative"
},
{
"test_id": 6,
"patient_id": 2,
"test_date": "2026-01-04",
"result": "Negative"
},
{
"test_id": 7,
"patient_id": 3,
"test_date": "2026-01-01",
"result": "Positive"
}
]
}[
{
"patient_id": 2,
"patient_name": "Bo",
"age": 40,
"recovery_time": 3
},
{
"patient_id": 1,
"patient_name": "Ava",
"age": 30,
"recovery_time": 4
}
]Bo's same-day negative does not count; the later negative gives three days. Ava's interval crosses a month boundary and is four days.
Constraints
Related LeetCode Problems
Practice more problems similar to Find COVID Recovery Patients.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.