Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the arrival times array.
DSA C++
std::sort(arr, arr + [1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable for array length.
Sorting the departure array instead of arrival.
✗ Incorrect
We sort the arrival times array from index 0 to n to process trains in order of arrival.
2fill in blank
mediumComplete the code to initialize the platform count to 1.
DSA C++
int platform_needed = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Initializing platform count to zero.
Using negative numbers.
✗ Incorrect
At least one platform is needed initially for the first train.
3fill in blank
hardFix the error in the while loop condition to compare arrival and departure times correctly.
DSA C++
while (i < n && j < n && arr[i] [1] dep[j]) {
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or equal instead of less than.
Confusing arrival and departure arrays.
✗ Incorrect
We check if the next train arrives before the earliest departure to decide platform allocation.
4fill in blank
hardFill both blanks to update platform count and move pointers correctly inside the loop.
DSA C++
if (arr[i] [1] dep[j]) { platform_needed++; i[2]; } else { j++; platform_needed--; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operator.
Decrementing i instead of incrementing.
✗ Incorrect
If arrival is less than departure, increase platform count and move arrival pointer forward.
5fill in blank
hardFill all three blanks to track the maximum platforms needed during the process.
DSA C++
int max_platforms = 1; while (i < n && j < n) { if (arr[i] [1] dep[j]) { platform_needed++; max_platforms = std::max(max_platforms, [2]); i[3]; } else { j++; platform_needed--; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Not updating max_platforms correctly.
Using wrong operators for comparison or increment.
✗ Incorrect
We update max_platforms with the current platform_needed and increment i when arrival is less than departure.
