Applied AI Engineer (LLM) coding learning path Level 2 This level · 17 of 31

Design Underground System

Medium Design Hash map

Problem

Track customers checking in and out of an underground system, and return the average travel time between two stations. A customer can be in at most one journey at a time, and they always check out after checking in.

Original: LeetCode 1396: Design Underground System.

Examples

Example 1

Input`UndergroundSystem: checkIn(45, "Leyton", 3), checkIn(32, "Paradise", 8), checkIn(27, "Leyton", 10), checkOut(45, "Waterloo", 15), checkOut(27, "Waterloo", 20), checkOut(32, "Cambridge", 22), getAverageTime("Paradise", "Cambridge"), getAverageTime("Leyton", "Waterloo"), checkIn(10, "Leyton", 24), getAverageTime("Leyton", "Waterloo"), checkOut(10, "Waterloo", 38), getAverageTime("Leyton", "Waterloo")`
Output`[null, null, null, null, null, null, 14.0, 11.0, null, 11.0, null, 12.0]`

Constraints

  • 1 <= id, t <= 10^6
  • 1 <= stationName.length, startStation.length, endStation.length <= 10
  • All strings consist of uppercase and lowercase English letters and digits.
  • There will be at most 2 * 10^4 calls in total to checkIn, checkOut, and getAverageTime.
  • Answers within 10^-5 of the actual value will be accepted.

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (1)
  1. LeetCode 1396: Design Underground Systemleetcode.com
Previous
Next