0
0
DSA Typescriptprogramming~30 mins

Minimum Number of Platforms in DSA Typescript - Build from Scratch

Choose your learning style9 modes available
Minimum Number of Platforms
📖 Scenario: You are managing a small train station. You want to find out the minimum number of platforms needed so that no train has to wait.Each train has an arrival time and a departure time.
🎯 Goal: Build a program that calculates the minimum number of platforms required for the trains given their arrival and departure times.
📋 What You'll Learn
Create two arrays called arrivals and departures with exact train times.
Create a variable called n to store the number of trains.
Write logic to find the minimum number of platforms needed using the arrival and departure arrays.
Print the minimum number of platforms required.
💡 Why This Matters
🌍 Real World
Train stations and airports use this logic to manage platforms or gates so that vehicles do not wait and operations run smoothly.
💼 Career
This problem teaches how to handle overlapping intervals and resource allocation, which is useful in scheduling, event planning, and system design roles.
Progress0 / 4 steps
1
Create train arrival and departure arrays
Create an array called arrivals with these exact values: 900, 940, 950, 1100, 1500, 1800. Also create an array called departures with these exact values: 910, 1200, 1120, 1130, 1900, 2000.
DSA Typescript
Hint

Use const arrivals = [...] and const departures = [...] with the exact numbers given.

2
Create variable for number of trains
Create a variable called n and set it to the length of the arrivals array.
DSA Typescript
Hint

Use const n = arrivals.length; to get the number of trains.

3
Calculate minimum number of platforms needed
Write code to calculate the minimum number of platforms needed. Sort the arrivals and departures arrays. Use two pointers i and j starting at 0. Use variables platforms_needed and max_platforms initialized to 0. Loop while i < n and j < n. If arrivals[i] <= departures[j], increment platforms_needed and i. Else decrement platforms_needed and increment j. Update max_platforms with the maximum of itself and platforms_needed inside the loop.
DSA Typescript
Hint

Sort both arrays. Use two pointers and count platforms needed. Update max platforms inside the loop.

4
Print the minimum number of platforms
Print the value of max_platforms.
DSA Typescript
Hint

Use console.log(max_platforms); to print the result.