solidcodersolidcoder
Explore Courses
solidcodersolidcoder

Practical courses for software engineering interviews — no gatekeeping, no fluff.

Company-wise Questions

  • Flipkart Machine Coding Questions
  • Swiggy Machine Coding Questions
  • Meesho Machine Coding Questions

Machine Coding Tutorial

  • Machine Coding Tutorial

Explore

  • Courses
  • About
  • Privacy Policy
  • Terms

© 2026 solidcoder · Practical courses for software engineering interviews.

Built for the AI era — learn by doing.

Home/Machine Coding/Meesho Machine Coding Questions/Car Pooling Service
Chapters — Meesho Machine Coding Questions▾

Car Pooling Service

Machine Coding·SDE-2+·5 min read·Sep 11, 2026

Design a car-pooling service matching drivers and passengers by proximity — nearby search, nearest-ride booking with fallback, and a concurrency follow-up.

Asked inMeesho

Design an in-memory car-pooling service that manages ride offers and bookings between drivers and passengers. All coordinates are given as latitude and longitude in floating point numbers.

What the round tests

This one tests whether you can combine geometric proximity search with stateful booking logic cleanly — nearest-ride selection, seat-capacity bookkeeping, and idempotent ride creation — while staying ready to reason about concurrency out loud when the interviewer pushes on it.

Distance model

For distance checks, treat the Earth as a flat plane and apply the Euclidean distance formula between two (lat, lng) points — no need for the Haversine formula or real great-circle distance. A ride counts as nearby if the straight-line distance between the driver's start point and the passenger's requested start point is ≤ 5 km.

Objective

The primary objective of this project is to design and implement an in-memory service where drivers register rides with seat capacity, passengers discover nearby rides sorted by distance, bookings decrement seats with a fallback to the next-nearest ride when one is full, and cancellations and ride history are tracked correctly per passenger.

Functional Requirements

Two tiers of scope

Requirements are split into two tiers so you know what to prioritize under time pressure: build first, and worth proposing if time allows.

Part 1 — Core Operations

Core functionality you must build and get working first.

Core operations
Operation
Behavior
Add ride
Input: rideId (auto-generated), startLat, startLng, endLat, endLng, driverName, maxSeatCapacity. Registers a new ride with the stated seat capacity.
Find nearby rides
Input: personId (auto-generated), personName, startLat, startLng, endLat, endLng. Returns every ride whose driver start location is within 5 km of the requester's start location, sorted by ascending distance.
Book the nearest ride
Input: personName, rideId. Selects the closest eligible ride (nearest distance with at least one free seat) and records the booking, decrementing remaining seats.
Cancel a ride
Input: rideId, personName. Cancels a ride that the given person had booked.
Get ride history
Input: personId. Returns, in chronological order, the rides this passenger has booked.
Idempotency & booking edge cases

A duplicate rideId on Add ride must be rejected or ignored — the system must stay idempotent. On Book the nearest ride, if the requested ride's seat is full, the system should report that it's unable to book that ride and automatically fall back to the next-nearest ride that still has an available seat.

Part 2 — Suggested Extensions

Not in the original prompt — worth proposing if time allows

These extend naturally from the core five operations and are the kind of follow-up an interviewer is likely to ask about once the basics work.

Suggested additional features
Feature
Why it's worth adding
Update ride
Let a driver adjust maxSeatCapacity or cancel the entire ride outright, not just individual bookings.
Waitlist for full rides
Instead of only falling back to the next-nearest ride, let a passenger optionally queue for a full ride and get auto-booked if a seat frees up via cancellation.
Driver-side ride history
Symmetric to passenger ride history — let a driver see every ride they've offered and who booked each one.
Real great-circle distance
Swap the flat-plane Euclidean approximation for the Haversine formula, useful to discuss as a follow-up on accuracy at longer distances or near the poles.
Rating system
Let passengers rate drivers (and vice versa) after a completed ride, feeding into a trust or ranking signal.

Follow-Up Question: Concurrent Booking

How would you prevent two passengers from booking the last available seat at the same time?

Describe a locking, optimistic-concurrency, or compare-and-swap approach.

Approaches worth discussing
Approach
How it works
Pessimistic locking
Acquire a per-ride lock (e.g. a mutex keyed by rideId) before checking and decrementing seat count, releasing it after the booking commits. Simple and correct, but serializes all bookings for a popular ride.
Optimistic concurrency
Read the current seat count with a version number; on write, use compare-and-swap to update only if the version hasn't changed since the read. If it has, retry the read-check-write cycle. Avoids blocking, but can retry heavily under contention.
Atomic compare-and-swap primitive
Model remaining seats as an atomic integer and use a single CAS operation (decrement only if count > 0) instead of a separate lock — avoids the overhead of a full lock for a single-field update.

Example Usage: Full Walkthrough

Here's how a sample session might run end-to-end, one step at a time.

1. Add a ride

> addRide(startLat: 12.90, startLng: 77.60, endLat: 12.95, endLng: 77.65, driverName: "Ravi", maxSeatCapacity: 2)
✅ Ride r1 added. Driver: Ravi. Seats available: 2.

2. Find nearby rides for a passenger

> findNearbyRides(personName: "Alice", startLat: 12.905, startLng: 77.602, endLat: 12.95, endLng: 77.66)
📍 Nearby rides (within 5 km), sorted by distance:
 - r1  Ravi  distance: 0.6 km  seats available: 2

3. Book the nearest ride

> bookNearestRide(personName: "Alice", rideId: "r1")
✅ Alice booked ride r1. Seats remaining: 1.

4. A second and third passenger book the same ride — one hits the fallback

> bookNearestRide(personName: "Bob", rideId: "r1")
✅ Bob booked ride r1. Seats remaining: 0.

> bookNearestRide(personName: "Carla", rideId: "r1")
❌ Ride r1 is full. Falling back to next-nearest ride with availability...
✅ Carla booked ride r2. Seats remaining: 1.

5. Cancel a booking

> cancelRide(rideId: "r1", personName: "Bob")
✅ Bob's booking on ride r1 canceled. Seats remaining: 1.

6. Check a passenger's ride history

> getRideHistory(personId: "alice-id")
🧾 Ride history for Alice:
 - r1  Ravi  booked at step 3
Result

Alice books the nearest ride outright; Bob fills the last seat; Carla's attempt on the same full ride correctly falls back to the next-nearest ride with space. Canceling Bob's booking frees a seat on r1 without disturbing Alice's or Carla's separate bookings.

Guidelines

Format & constraints

This is a 90-minute round with the interviewer present. Code is written and executed on HackerRank, and will be tested against input the interviewer provides directly — so the solution needs to run correctly as a standalone program, not just look right on paper.

Up next2/2
Part 1 · SDE-2+
←
← Prev Chapter
Inventory Management
5 min
Next Chapter →
Gym Chain Booking
5 min · continue reading
→

Enroll in machine coding mastery series

₹30,000₹3,00090% OFF
Enroll Now →

Use code SOLID50 · 3 years · 40+ lessons

On this page
  • Objective
  • Functional Requirements
    • Part 1 — Core Operations
    • Part 2 — Suggested Extensions
  • Follow-Up Question: Concurrent Booking
  • Example Usage: Full Walkthrough
  • Guidelines