Ride queue board
MediumOnline Assessment
Compute the wait times a theme park should post on its board right now, from the scans at the ride entrances and boarding gates.
Each scan is a string "<minute> <ride> <guest> <kind>", such as "615 comet-coaster g42 in". minute counts from park opening; kind is in (the guest scanned into the queue) or out (the guest scanned at the boarding gate). The scans were merged from several scanners, so they are not in time order. Only scans with minute <= now are known; ignore the rest. Process the known scans in increasing minute; scans with the same minute keep their order in scans.
A guest has at most one pending entry per ride:
inwhen the guest is already pending on that ride is a duplicate scan and is ignored (the earlier time stands).inotherwise makes the guest pending, starting at that minute.outwhen the guest is pending finishes a wait ofout minute - in minuteminutes and ends the pending entry. Anoutwith no pending entry is ignored.
Guests whose id starts with fp hold fast passes. Their waits are finished like any other, but they are never used for the board. For each ride, the usable waits are the non-fast-pass waits whose out minute is greater than now - 45. The ride's posted wait is the mean of its (up to) four usable waits with the latest out minutes (a later scan counts as later when minutes are equal), rounded to the nearest multiple of 5, with a mean exactly halfway between two multiples rounded up. A ride with no usable waits posts -1.
Input: scans, a list of strings, and now, an integer.
Output: a list [ride, posted] for every ride that has at least one known scan, ordered by posted ascending with rides that post -1 last; equal posted waits are ordered alphabetically by ride name. Return [] if there are no known scans.
Example 1
- Input:
- [["20 comet g1 in","30 comet g2 in","50 comet g1 out","60 comet g3 in","62 comet fp1 in","64 comet fp1 out","70 comet g4 in","75 comet g3 out","85 comet g2 out","95 comet g4 out","10 yeti g1 in","20 yeti g1 out","60 kraken k1 in","72 kraken k1 out","70 kraken k2 in","83 kraken k2 out","120 comet g9 in","130 ghost g1 in"],100]
- Output:
- [["kraken",15],["comet",30],["yeti",-1]]
- Explanation
- At
now = 100, the scan at 120 and the rideghostare ignored. Forcomet, the wait of guestg1ended at minute 50, which is not after 55, so it is stale. The usable waits areg3(15),g2(55) andg4(25);fp1is a fast pass. The mean is 31.67, posted as 30.krakenhas waits 12 and 13: mean 12.5 is halfway, so it rounds up to 15.yetionly has a stale wait and posts -1, which sorts last.
Example 2
- Input:
- [["110 rapids a1 in","120 rapids a1 in","130 rapids a2 out","150 rapids a1 out","90 rapids c1 in","120 rapids c1 out","100 rapids c2 in","125 rapids c2 out","120 rapids b1 in","130 rapids b1 out","118 rapids b2 in","133 rapids b2 out","135 rapids e1 in","140 rapids e1 out","152 rapids a1 in","158 rapids a1 out","140 rapids d1 in","160 rapids d1 out","100 tilt fp9 in","110 tilt fp9 out"],160]
- Output:
- [["rapids",20],["tilt",-1]]
- Explanation
- The second
inofa1is a duplicate, so its wait is 40, not 30. Theoutofa2has no pending entry and is ignored. Guesta1can queue again after finishing a wait (the 6-minute wait at 158). Eight waits are usable forrapids, so only the four with the latestoutminutes count: 5, 40, 6 and 20, mean 17.75, which posts 20.tiltonly has a fast-pass guest, so it posts -1.
Example 3
- Input:
- [["200 loop z in","200 loop z out","190 spin y in","190 spin y out","100 dock w in","155 dock w out","180 tower t1 in","182 tower t1 out","185 tower t2 in","188 tower t2 out"],200]
- Output:
- [["loop",0],["spin",0],["tower",5],["dock",-1]]
- Explanation
- A wait ending exactly at
now - 45is stale, one ending exactly atnowis usable.loopandspinboth post 0 (a wait of zero minutes is a wait) and are ordered by name;towerposts 5 from a mean of 2.5.
Constraints
0 <= scans.length <= 1,5000 <= now <= 1,440; every scan minute is between0and1,440- ride and guest ids are lowercase letters, digits and hyphens without spaces