Plan a station’s tracks by entering train arrival and departure times. The app computes the minimum number of tracks required so that all trains can be accommodated without conflicts.
- Open
index.htmlin a modern browser. - Add train rows (or set the number of trains and click "Apply Count").
- Enter arrival and departure times (24-hour format, supports
24:00). - Click "Calculate Minimum Tracks".
Use the "Input mode" toggle to switch to "Real station (India)". Provide:
- Station code (e.g., NDLS)
- Date (YYYY-MM-DD)
- API base URL (your endpoint that returns schedule JSON)
- API key (optional, if your API requires it)
Click "Fetch Schedule" to populate the table. The app expects an array of items or a property like trains, data, or results with arrival_time/departure_time (or similarly named) fields. If your API uses different field names, adapt the mapping in fetchStationSchedule within app.js.
Open app.js and implement your logic in the function:
function computeMinimumTracks(trains) {
// trains: Array<{ arrival: number, departure: number }>
// return a number
}Notes:
arrivalanddepartureare minutes since00:00.- Input is validated so
departure > arrivaland within00:00–24:00. - If you prefer, you can export/import from another file; just ensure
computeMinimumTracksis available globally or in this scope.
Below the result there’s a simple visualization that places trains into tracks with a greedy layout for display only. It is not used to compute the answer; it’s there to help sanity‑check inputs.
- No build step required; it’s plain HTML/CSS/JS.
- Tested in latest Chrome and Edge.