−65% Most banks now $169 $59.
Coding · 8 min read

Lyft's 3-Part Rating Service Question

Lyft coding rounds favor practical modeling over puzzles. This rating service hands you the real domain (riders and drivers rate each other after a ride) and asks you to model it, ingest a JSON feed, and answer two queries. The hidden test is what received rating actually means. Here is the full question, Java for all three parts, and a detailed rubric.


The question

After a Lyft ride, the rider rates the driver and the driver rates the rider, 1 to 5 stars. Given a database of rides and ratings, build a small service.

Part 1: design classes for the ride and rating objects. Part 2: transform the raw JSON feed into those objects. Part 3: build two APIs: the rating a user received on a given ride, and the average rating a user received.

getRatingForRideAndUser(3, 9012) == 1
getAverageRatingOfUser(5678)    == (4 + 2) / 2 == 3.0

Part 1 and 2 · Model and ingest

Model a ride and a rating as plain records. Ingestion deserializes the JSON feed into lists, then indexes them: ratings by ride, and the set of rides each user took. Those indexes are what make the Part 3 queries fast.

import java.util.*;

class RatingService {
    record Ride(int rideId, int driverId, int riderId, long timestamp) {}
    record Rating(int rideId, int fromUserId, int rating) {}

    private final Map<Integer, List<Rating>> ratingsByRide = new HashMap<>();
    private final Map<Integer, List<Integer>> ridesByUser = new HashMap<>();

    // Part 2: ingest the parsed feed (e.g. deserialized with Jackson) and index it.
    void load(List<Ride> rides, List<Rating> ratings) {
        for (Ride r : rides) {
            ridesByUser.computeIfAbsent(r.driverId(), k -> new ArrayList<>()).add(r.rideId());
            ridesByUser.computeIfAbsent(r.riderId(), k -> new ArrayList<>()).add(r.rideId());
        }
        for (Rating rt : ratings)
            ratingsByRide.computeIfAbsent(rt.rideId(), k -> new ArrayList<>()).add(rt);
    }
}

Part 3 · The two APIs

Here is the crux. The rating a user received on a ride is the one the other participant submitted, the rating whose author is not that user. The average is taken over every ride the user was part of.

    // The rating the user RECEIVED = submitted by the counterparty on that ride.
    Integer getRatingForRideAndUser(int rideId, int userId) {
        for (Rating rt : ratingsByRide.getOrDefault(rideId, List.of()))
            if (rt.fromUserId() != userId) return rt.rating();
        return null;   // counterparty never rated
    }

    // Average of all ratings the user received across their rides.
    double getAverageRatingOfUser(int userId) {
        int sum = 0, count = 0;
        for (int rideId : ridesByUser.getOrDefault(userId, List.of())) {
            Integer received = getRatingForRideAndUser(rideId, userId);
            if (received != null) { sum += received; count++; }
        }
        return count == 0 ? 0.0 : (double) sum / count;
    }

Check it against the examples: on ride 3, user 9012 received the rating authored by 6543, which is 1; user 5678 drove rides 1 and 2 and received 4 and 2, averaging 3.0. Read received as the counterparty submitted and the rest follows.

How Lyft scores it

Dimension Weak Strong
Domain semanticsReturns the rating the user gaveReturns the counterparty's rating (what the user received)
ModelingTangled or stringly-typed objectsClean ride and rating types
IngestionRe-scans lists per queryIndexes ratings by ride and rides by user
AverageCounts the user's own ratingsAverages only ratings received, across their rides
Edge casesCrashes on missing rating or unknown userReturns null or zero gracefully
ComplexityLinear scans everywhereO(1) ride lookup, O(rides) average

This is one question of 10 pages

Get the full Lyft question bank

The full Lyft bank carries the coding, API, and data-science rounds, each problem with its follow-ups and a rubric, compiled from people familiar with the process and cross-verified across sources.

Lyft interview FAQ

What does the Lyft coding interview ask?+

Real-world modeling and API problems drawn from Lyft's domain: rides, ratings, pricing. You design clean objects, ingest a raw feed, and implement query APIs, with correctness on the domain semantics mattering most.

What is the trick in the Lyft rating question?+

The rating a user received on a ride is the one submitted by the other participant, not the rating that user gave. Missing that inverts every answer. The average is over all ratings the user received across their rides.

How is the Lyft coding round scored?+

On clean object modeling, correct ingestion and indexing for fast lookups, the right received-rating semantics, a correct average, and edge cases like a missing counterparty rating or an unknown user.

Where can I find real Lyft interview questions?+

Pichup maintains a 10-page Lyft question bank compiled from people familiar with the process, with the coding, API, and data-science rounds, their follow-ups, and rubrics. The question in this guide is one of them.