Uber phone screen - Randomly select a driver from a stream of drivers
1364

When user sends a request to Uber ride, the service finds drivers nearby, and sends driver info in the form of a data stream to the application. The application will randomly choose a driver from the stream to pick up this user. You job is to build a method that will randomly selects a driver from the stream of drivers.

Considering the performance, the application must not load and keep information of all drivers at once. Instead, the method should process one driver after another, and discard previous drivers data when reading the next driver from stream. All drivers have equal chance to be chosen.

Comments (1)