DEV Community

Discussion on: Minimum Number of Platforms Required for a Railway Station, Bloomberg Interview question. 🚄🚄🚄

Collapse
akhilpokle profile image
Akhil Author

Hi ! thanks for your solution. Could you explain the flow of execution? I am not that well versed in javascript methods.

Collapse
majaleksander profile image
Aleksander Maj
  1. It merges an array of arrivals with departures and adds some values (1 when the train arrives and -1 when it departures). Result of it should be an array of sth like:
    [{time: 9:00, value: 1}, ....,{time: 2000, value: -1}]

  2. Then I sort it like you did it.

  3. .reduce is loop that's going through the "timetable" and it is doing two things:

    • add 1 if train comes and subtracts if it departures
    • check what is current number of trains and save max of this value
Thread Thread
akhilpokle profile image
Akhil Author

Wow! This is so efficient! Thanks for sharing it !!