0
0
DSA Cprogramming~30 mins

Minimum Number of Platforms in DSA C - Build from Scratch

Choose your learning style9 modes available
Minimum Number of Platforms
📖 Scenario: Imagine a small train station where trains arrive and depart at different times. We want to find out the minimum number of platforms needed so that no train has to wait.
🎯 Goal: You will write a program to find the minimum number of platforms required for the trains based on their arrival and departure times.
📋 What You'll Learn
Create two arrays called arrivals and departures with exact train times
Create an integer variable called n for the number of trains
Write a function called minPlatforms that takes arrivals, departures, and n as input and returns the minimum number of platforms needed
Print the result using printf
💡 Why This Matters
🌍 Real World
Train stations and airports use this logic to manage platforms and gates efficiently to avoid delays.
💼 Career
Understanding scheduling and resource allocation algorithms is important for software engineers working on transportation, logistics, and event management systems.
Progress0 / 4 steps
1
Create train arrival and departure arrays
Create two integer arrays called arrivals and departures with these exact values: arrivals = {900, 940, 950, 1100, 1500, 1800} and departures = {910, 1200, 1120, 1130, 1900, 2000}. Also create an integer variable called n and set it to 6.
DSA C
Hint

Use int arrivals[] = {...}; and int departures[] = {...}; to create the arrays. Set n to 6.

2
Declare the minPlatforms function
Declare a function called minPlatforms that takes three parameters: two integer arrays arrivals and departures, and an integer n. The function should return an integer.
DSA C
Hint

Write the function declaration with the correct parameters and return type.

3
Implement the minPlatforms function logic
Implement the minPlatforms function to calculate the minimum number of platforms needed. Use sorting for arrivals and departures, then use two pointers to count platforms needed. Return the maximum platforms required.
DSA C
Hint

Sort both arrays. Use two indexes i and j to traverse arrivals and departures. Increase platform count if arrival is before or equal to departure, else decrease. Track max platforms.

4
Print the minimum number of platforms
Call the minPlatforms function with arrivals, departures, and n. Store the result in an integer variable called result. Then print Minimum number of platforms needed: followed by result using printf.
DSA C
Hint

Call minPlatforms(arrivals, departures, n), store in result, then print with printf.