0
0
DSA Cprogramming~20 mins

Minimum Number of Platforms in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Platform Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the minimum number of platforms needed?
Given arrival and departure times of trains, what is the minimum number of platforms required so that no train waits?
DSA C
int findPlatform(int arr[], int dep[], int n) {
    int platform_needed = 1, result = 1;
    int i = 1, j = 0;
    while (i < n && j < n) {
        if (arr[i] <= dep[j]) {
            platform_needed++;
            i++;
            if (platform_needed > result)
                result = platform_needed;
        } else {
            platform_needed--;
            j++;
        }
    }
    return result;
}

// Example usage:
// arr = {900, 940, 950, 1100, 1500, 1800}
// dep = {910, 1200, 1120, 1130, 1900, 2000}
// n = 6
// printf("%d", findPlatform(arr, dep, n));
A3
B4
C2
D5
Attempts:
2 left
💡 Hint
Sort arrival and departure times and compare them to find overlaps.
Predict Output
intermediate
2:00remaining
Output of platform calculation with unsorted input arrays
What will be the output of the function if arrival and departure arrays are not sorted?
DSA C
int findPlatform(int arr[], int dep[], int n) {
    int platform_needed = 1, result = 1;
    int i = 1, j = 0;
    while (i < n && j < n) {
        if (arr[i] <= dep[j]) {
            platform_needed++;
            i++;
            if (platform_needed > result)
                result = platform_needed;
        } else {
            platform_needed--;
            j++;
        }
    }
    return result;
}

// Example usage:
// arr = {950, 900, 1100, 940, 1500, 1800}
// dep = {1120, 910, 1130, 1200, 1900, 2000}
// n = 6
// printf("%d", findPlatform(arr, dep, n));
A3
B2
C1
D4
Attempts:
2 left
💡 Hint
The function assumes sorted arrays; unsorted input breaks logic.
🧠 Conceptual
advanced
1:30remaining
Why sorting arrival and departure times is essential?
Why must arrival and departure arrays be sorted before calculating minimum platforms?
ATo ensure trains are processed in chronological order to detect overlaps correctly.
BTo reduce the time complexity from O(n^2) to O(n log n).
CTo group trains by their platform number.
DTo avoid using extra memory for storing platforms.
Attempts:
2 left
💡 Hint
Think about how overlapping intervals are detected.
🔧 Debug
advanced
2:00remaining
Identify the bug in this platform calculation code
What is the bug in this code snippet for finding minimum platforms?
DSA C
int findPlatform(int arr[], int dep[], int n) {
    int platform_needed = 1, result = 1;
    int i = 0, j = 0;
    while (i < n && j < n) {
        if (arr[i] < dep[j]) {
            platform_needed++;
            i++;
            if (platform_needed > result)
                result = platform_needed;
        } else {
            platform_needed--;
            j++;
        }
    }
    return result;
}
AThe initial value of i should be 1, not 0.
BThe function should return platform_needed instead of result.
CThe platform_needed should never be decremented.
DThe comparison should be arr[i] <= dep[j], not arr[i] < dep[j].
Attempts:
2 left
💡 Hint
Consider trains arriving exactly when another departs.
🚀 Application
expert
2:30remaining
Calculate platforms for large input with overlapping trains
Given these arrival and departure times, what is the minimum number of platforms needed? arr = {100, 140, 150, 200, 215, 400} dep = {110, 300, 220, 230, 315, 600} n = 6
A3
B4
C5
D6
Attempts:
2 left
💡 Hint
Sort arrays and count maximum overlaps step-by-step.