Skip to content

Practice Trips and Users

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#262
LeetCode Problem

Trips and Users

Problem Statement

Tables: Trips(id INT, client_id INT, driver_id INT, city_id INT, status ENUM, request_at VARCHAR); Users(users_id INT, banned ENUM, role ENUM). Trips.id and Users.users_id are unique. Trips.client_id and driver_id reference Users.users_id. status is completed, cancelled_by_driver or cancelled_by_client; banned is Yes or No; role is client, driver or partner. For each date from 2013-10-01 through 2013-10-03 having at least one eligible trip, return Day and Cancellation Rate rounded to two decimals. A trip is eligible only when both client and driver are unbanned. Divide eligible cancelled trips, by either party, by all eligible trips on that date. Output order is unrestricted.

Source: Trips and Users on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
Trips table: +----+-----------+-----------+---------+---------------------+------------+ | id | client_id | driver_id | city_id | status              | request_at | +----+-----------+-----------+---------+---------------------+------------+ | 1  | 1         | 10        | 1       | completed           | 2013-10-01 | | 2  | 2         | 11        | 1       | cancelled_by_driver | 2013-10-01 | | 3  | 3         | 12        | 6       | completed           | 2013-10-01 | | 4  | 4         | 13        | 6       | cancelled_by_client | 2013-10-01 | | 5  | 1         | 10        | 1       | completed           | 2013-10-02 | | 6  | 2         | 11        | 6       | completed           | 2013-10-02 | | 7  | 3         | 12        | 6       | completed           | 2013-10-02 | | 8  | 2         | 12        | 12      | completed           | 2013-10-03 | | 9  | 3         | 10        | 12      | completed           | 2013-10-03 | | 10 | 4         | 13        | 12      | cancelled_by_driver | 2013-10-03 | +----+-----------+-----------+---------+---------------------+------------+ Users table: +----------+--------+--------+ | users_id | banned | role   | +----------+--------+--------+ | 1        | No     | client | | 2        | Yes    | client | | 3        | No     | client | | 4        | No     | client | | 10       | No     | driver | | 11       | No     | driver | | 12       | No     | driver | | 13       | No     | driver | +----------+--------+--------+
Output
+------------+-------------------+ | Day        | Cancellation Rate | +------------+-------------------+ | 2013-10-01 | 0.33              | | 2013-10-02 | 0.00              | | 2013-10-03 | 0.50              | +------------+-------------------+

Related LeetCode Problems

Practice more problems similar to Trips and Users.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.