Apple OA Interview Question: Maximum 8-Hour Trip Earnings by Driver

16 Views
No Comments

Given a Trip table, find each driver's consecutive 8-hour period with the highest total trip earnings.

A window starts at any trip's start_time and includes that driver's trips starting within the following 8 hours.

Rank drivers by their maximum 8-hour earnings and calculate a 10% bonus.

This problem asks you to compute, for each driver, the maximum total earnings within any consecutive 8-hour window starting from a trip's start time. A typical solution groups trips by driver, sorts each group by start time, and uses a sliding window or two pointers to maintain the trips that fall within the next 8 hours while tracking the running sum. After finding each driver's peak 8-hour earnings, you rank drivers by that value and compute the 10% bonus.

END
 0