Building on the Hopper series, the Hopper Company Queries II coding problem asks for the "working percentage" of drivers for each month of 2020. The working percentage is defined as the number of drivers who accepted at least one ride in a month divided by the total number of active drivers (drivers who joined on or before that month). The result should be rounded to two decimal places.
Companies like Uber ask this to evaluate a candidate's ability to handle multi-layered aggregations and arithmetic in SQL. It tests whether you can maintain context across different groupings (e.g., total drivers joined vs. drivers active in rides) and handle potential "division by zero" errors or NULL values gracefully.
The pattern involves Relational Aggregation and Ratio Calculation:
AcceptedRides table for that month).WorkingDrivers / ActiveDrivers * 100. Use IFNULL or COALESCE to handle months with no activity.NULL instead of 0.00 for months with no active drivers or rides.ROUND(..., 2) function as specified.Always consider the "denominator." In ratio problems, defining exactly what constitutes the total population (the active drivers) versus the sub-population (working drivers) is the key to accuracy.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Hopper Company Queries I | Hard | Solve | |
| Hopper Company Queries III | Hard | Solve | |
| Human Traffic of Stadium | Hard | Solve | |
| Trips and Users | Hard | Solve | |
| Analyze Organization Hierarchy | Hard | Solve |