Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the arrival times array.
DSA C#
Array.[1](arrival);Attempts:
3 left
💡 Hint
Common Mistakes
Using Array.Reverse which reverses the array instead of sorting.
Using Array.Clear which empties the array.
Using Array.Copy which copies elements but does not sort.
✗ Incorrect
We use Array.Sort to sort the arrival times so we can process trains in order.
2fill in blank
mediumComplete the code to sort the departure times array.
DSA C#
Array.[1](departure);Attempts:
3 left
💡 Hint
Common Mistakes
Using Array.Clear which removes all elements.
Using Array.Reverse which reverses order incorrectly.
✗ Incorrect
Sorting departure times helps us track when platforms get free.
3fill in blank
hardFix the error in the while loop condition to correctly compare arrival and departure times.
DSA C#
while (i < n && j < n && arrival[i] [1] departure[j])
Attempts:
3 left
💡 Hint
Common Mistakes
Using >= or > which reverses the logic.
Using <= which includes equality incorrectly.
✗ Incorrect
We check if the next train arrives before the earliest departure to decide platform count.
4fill in blank
hardFill both blanks to update platform count correctly inside the loop.
DSA C#
if (arrival[i] [1] departure[j]) { platforms_needed[2]; i++; } else { platforms_needed--; j++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' instead of '<' in comparison.
Decrementing platforms_needed when a train arrives.
✗ Incorrect
If arrival is before departure, we add a platform. So we use '<' and increment platforms_needed.
5fill in blank
hardFill all three blanks to update the maximum platforms needed.
DSA C#
max_platforms = Math.[1](max_platforms, platforms_needed[2]); // Move to next arrival or departure if (arrival[i] [3] departure[j]) { i++; } else { j++; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Math.Min instead of Math.Max.
Using '>' instead of '<' in the if condition.
Adding instead of comparing platforms_needed.
✗ Incorrect
We update max_platforms with the max of current max and platforms_needed. Then move pointers based on arrival < departure.
