Challenge - 5 Problems
Platform Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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));
Attempts:
2 left
💡 Hint
Sort arrival and departure times and compare them to find overlaps.
✗ Incorrect
The function counts how many trains overlap at any time. The maximum overlap is the minimum number of platforms needed.
❓ Predict Output
intermediate2: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));
Attempts:
2 left
💡 Hint
The function assumes sorted arrays; unsorted input breaks logic.
✗ Incorrect
Without sorting, the function compares times incorrectly, leading to wrong platform count.
🧠 Conceptual
advanced1:30remaining
Why sorting arrival and departure times is essential?
Why must arrival and departure arrays be sorted before calculating minimum platforms?
Attempts:
2 left
💡 Hint
Think about how overlapping intervals are detected.
✗ Incorrect
Sorting allows comparing arrival and departure times in order, so overlaps are detected accurately.
🔧 Debug
advanced2: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; }
Attempts:
2 left
💡 Hint
Consider trains arriving exactly when another departs.
✗ Incorrect
Using < misses the case when arrival equals departure, causing incorrect platform count.
🚀 Application
expert2: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
Attempts:
2 left
💡 Hint
Sort arrays and count maximum overlaps step-by-step.
✗ Incorrect
Maximum overlap occurs between trains arriving at 140, 150, 200, and 215, requiring 4 platforms.