Practice Find Drivers with Improved Fuel Efficiency
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: drivers(driver_id INT, driver_name VARCHAR) and trips(trip_id INT, driver_id INT, trip_date DATE, distance_km DECIMAL, fuel_consumed DECIMAL). Calculate each trip's efficiency as distance divided by fuel. Compare the arithmetic mean of trip efficiencies in January-June with July-December. Keep drivers present in both halves whose second mean is greater. Return driver_id, driver_name, first_half_avg, second_half_avg, and efficiency_improvement (second mean minus first), rounded to two decimals. Sort by improvement descending, then driver_name ascending. Practice approach: Average per-trip ratios conditionally by month. The ratio of total distance to total fuel is a different weighted measure. Preserve precision until calculating the final difference and rounding output values.
Source: Find Drivers with Improved Fuel Efficiency on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
{
"drivers": [
{
"driver_id": 1,
"driver_name": "Ava"
},
{
"driver_id": 2,
"driver_name": "Bo"
},
{
"driver_id": 3,
"driver_name": "Cy"
},
{
"driver_id": 4,
"driver_name": "Dee"
}
],
"trips": [
{
"trip_id": 1,
"driver_id": 1,
"trip_date": "2026-01-01",
"distance_km": 100,
"fuel_consumed": 10
},
{
"trip_id": 2,
"driver_id": 1,
"trip_date": "2026-06-01",
"distance_km": 60,
"fuel_consumed": 3
},
{
"trip_id": 3,
"driver_id": 1,
"trip_date": "2026-07-01",
"distance_km": 80,
"fuel_consumed": 4
},
{
"trip_id": 4,
"driver_id": 2,
"trip_date": "2026-01-01",
"distance_km": 50,
"fuel_consumed": 5
},
{
"trip_id": 5,
"driver_id": 2,
"trip_date": "2026-07-01",
"distance_km": 40,
"fuel_consumed": 5
},
{
"trip_id": 6,
"driver_id": 3,
"trip_date": "2026-01-01",
"distance_km": 50,
"fuel_consumed": 5
},
{
"trip_id": 7,
"driver_id": 4,
"trip_date": "2026-01-01",
"distance_km": 8,
"fuel_consumed": 3
},
{
"trip_id": 8,
"driver_id": 4,
"trip_date": "2026-07-01",
"distance_km": 10,
"fuel_consumed": 3
}
]
}[
{
"driver_id": 1,
"driver_name": "Ava",
"first_half_avg": 15,
"second_half_avg": 20,
"efficiency_improvement": 5
},
{
"driver_id": 4,
"driver_name": "Dee",
"first_half_avg": 2.67,
"second_half_avg": 3.33,
"efficiency_improvement": 0.67
}
]Ava's first-half mean is (10+20)/2=15 rather than 160/13. Bo worsens and Cy lacks second-half trips. Dee improves by 10/3 - 8/3 = 2/3, rounded to 0.67; subtracting rounded means would incorrectly give 0.66.
Constraints
Related LeetCode Problems
Practice more problems similar to Find Drivers with Improved Fuel Efficiency.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.