Practice/Uber/Leetcode 262. Trips and Users
CodingOptional
You are building an analytics dashboard for a ride-sharing platform. The platform needs to monitor the daily cancellation rate of rides to identify operational issues and maintain service quality.
Given two data tables and a date range, calculate the cancellation rate for each day that has at least one valid trip. A trip is considered valid only if both the client and driver associated with it are not banned from the platform.
The cancellation rate for a given day is defined as:
A trip is considered cancelled if its status is either "cancelled_by_client" or "cancelled_by_driver". Completed trips have status "completed".
Example 1:
` Trips: | trip_id | client_id | driver_id | request_date | status | |---------|-----------|-----------|--------------|--------| | 1 | 101 | 201 | 2024-01-15 | completed | | 2 | 102 | 202 | 2024-01-15 | cancelled_by_driver | | 3 | 103 | 201 | 2024-01-16 | cancelled_by_client | | 4 | 104 | 202 | 2024-01-16 | completed |
Users: | user_id | banned | role | |---------|--------|------| | 101 | No | client | | 102 | No | client | | 103 | No | client | | 104 | Yes | client | | 201 | No | driver | | 202 | No | driver |
Date range: 2024-01-15 to 2024-01-16
Output: {'2024-01-15': 0.50, '2024-01-16': 1.00}
Explanation:
Example 2:
` Trips: | trip_id | client_id | driver_id | request_date | status | |---------|-----------|-----------|--------------|--------| | 1 | 101 | 201 | 2024-02-01 | completed | | 2 | 102 | 202 | 2024-02-01 | completed | | 3 | 103 | 201 | 2024-02-01 | completed |
Users: | user_id | banned | role | |---------|--------|------| | 101 | No | client | | 102 | No | client | | 103 | No | client | | 201 | No | driver | | 202 | No | driver |
Date range: 2024-02-01 to 2024-02-01
Output: {'2024-02-01': 0.00}
Explanation: All 3 trips are valid and completed, so cancellation rate is 0/3 = 0.00 `