Feature #1: Select Closest Drivers

Implementing the "Select Closest Drivers" feature for our "Uber" project.


The first functionality we’ll be building is to locate the nearest available drivers within the vicinity of a user. There are numerous Uber drivers roaming around in a city. For simplicity, we’ll consider the city as a Cartesian plane and assign the coordinates (0, 0) to the user’s location. When a user wants to book a ride, we’ll simply find k drivers with the shortest distance on the Cartesian plane. Here, k is the minimum threshold for choosing the closest drivers.

We’ll be provided a list containing a set of points on the Cartesian plane and a number k. Each set of points will represent the location of a driver. We need to find the k closest drivers from the user’s location.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.