Interview Query

Random Weighted Driver

4
Have you seen this question before?

Let’s say we want to improve the matching algorithm for drivers and riders for Uber. The engineering team has added a column to the drivers table with a weighted value for better matching.

Given this table of drivers, write a query to perform a weighted random selection of a driver based on the driver weight.

Example:

Input:

drivers table

Column Type
id INTEGER
weighting INTEGER

Output:

Column Type
id INTEGER
Next question: Loan Model
.....
MySQL 8.0.17
Loading editor
Use Shift + Enter to run query