Average Campus Shuttle Ride Time Between Any Two Stops

Last updated: November 29, 2026

Quick Overview

Riders badge in at a stop and badge out at another stop. Design a tracker with check_in(rider, stop, t), check_out(rider, stop, t) and average_time(start, end), which returns the mean duration of completed trips from start to end.

Meta
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Riders badge in at a stop and badge out at another stop. Design a tracker with check_in(rider, stop, t), check_out(rider, stop, t) and average_time(start, end), which returns the mean duration of completed trips from start to end.

A practical Meta screen question framed around the shuttles between Menlo Park and San Francisco offices. The interviewer checks that you separate in-flight state from aggregated stats and keep every operation O(1).

What the Interviewer Expects
  • Separate open trips from completed route aggregates
  • Key aggregates by ordered (start, end) pairs
  • Store total and count rather than every trip
  • Allow a rider to make many trips over time
  • Clarify behavior for routes with no completed trips
Key Topics to Cover
Hash map
Running aggregates
Stateful design
Object-oriented design
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you report the median instead of the mean?
  • How would you report the average over only the last 7 days?
  • What if a rider badges in twice without badging out?
  • How would this scale to a city transit system with millions of riders?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • A rider has at most one open trip at a time.
  • Directions matter: A to B is a different route from B to A.
  • average_time is asked only for routes, or we raise if no trip completed....
High-Level Design

Use two maps. open_trips maps a rider to their start stop and time and is cleared on check-out. route_stats maps (start, end) to a running [total_time, count]. Check-out pops the rider's open ...


Submit Your Answer
Markdown supported