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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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_timeis 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 ...