1407. Top Travellers LeetCode Solution
In this guide, you will get 1407. Top Travellers LeetCode Solution with the best time and space complexity. The solution to Top Travellers problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Top Travellers solution in C++
- Top Travellers solution in Java
- Top Travellers solution in Python
- Additional Resources
Problem Statement of Top Travellers
Table: Users
+—————+———+
| Column Name | Type |
+—————+———+
| id | int |
| name | varchar |
+—————+———+
id is the column with unique values for this table.
name is the name of the user.
Table: Rides
+—————+———+
| Column Name | Type |
+—————+———+
| id | int |
| user_id | int |
| distance | int |
+—————+———+
id is the column with unique values for this table.
user_id is the id of the user who traveled the distance “distance”.
Write a solution to report the distance traveled by each user.
Return the result table ordered by travelled_distance in descending order, if two or more users traveled the same distance, order them by their name in ascending order.
The result format is in the following example.
Example not found
Constraints not found
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
1407. Top Travellers LeetCode Solution in C++
SELECT
Users.name,
IFNULL(SUM(Rides.distance), 0) AS travelled_distance
FROM Users
LEFT JOIN Rides
ON (Users.id = Rides.user_id)
GROUP BY Users.id
ORDER BY 2 DESC, 1;
/* code provided by PROGIEZ */
1407. Top Travellers LeetCode Solution in Java
N/A
// code provided by PROGIEZ
1407. Top Travellers LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.