## Uber Interview Question for Backend Developers

Country: United States
Interview Type: In-Person

Comment hidden because of low score. Click to expand.
0
of 0 vote

We can use an 2-d array as a Data structure. (By assuming all the cabs are discretely present inside a cell).
We can always calculate the distance from the focal point, from which the cab is called.

Comment hidden because of low score. Click to expand.
0
of 0 vote

But in this case u need to calculate distances for all cab points from the focal point, we need to do this more efficiently.

Comment hidden because of low score. Click to expand.
0
of 0 vote

use geohash, and tries on that . we can find the nearest cabs which are following under same parent.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Basically they wanted me to implement geohash. Any hints how to go abt that?

Comment hidden because of low score. Click to expand.
0
of 0 vote

Quadtrees ? In case it was from a design perspective

Comment hidden because of low score. Click to expand.
0
of 0 vote

Quadtrees ? In case it was from a design perspective

Comment hidden because of low score. Click to expand.
0
of 0 vote

Quadtrees ? In case it was from a design perspective

Comment hidden because of low score. Click to expand.
0
of 0 vote

Maintain a grid of latitude and longitude of some particular length and set of cabs in each grid element.

So if a cab moves from one grid to another. You can update the grid sets in O(1) time.

When a user at position(uLat,uLong) queries for cabs within a radius r, we will process all grid elements between (uLat-r) to (uLat+r) and (uLong-r) to (uLong+r). For every cab in such grid element, we check whether they are at a distance r from the user. This takes O(total no. of cabs considered) or O(total no. of grids considered) time.

Comment hidden because of low score. Click to expand.
0
of 0 vote

You can use BFS. start from source node and mark distance as 0. If any point in time if distance of node exceeds radius. then return back.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Consider if need to calculate the distances between coordinates, to be efficient hash can easily avoid recalculating the distances of two coordinates.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Simply use a K-D tree using long and lang as 2 dimensions of each node and build a K-D tree based on long, lat of all cabs and search the position of user in the K-D tree and while searching check if euclid dist(user,cab) <=R.

Updation: O(logn)/ O(d)
Search: O(logn)/ O(d)
d->max depth of K-D tree.
n->current number of cabs.

A more refined solution will be to create a grid for the location by maintaining a K-D tree with a threshold depth and group cabs according to criteria then simply search with user's location and assign valid groups.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.