Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to read the number of trains.
DSA C
int n; scanf("%[1]", &n);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using %f or %c instead of %d for integer input.
Forgetting the ampersand (&) before the variable.
✗ Incorrect
The format specifier %d is used to read an integer in C.
2fill in blank
mediumComplete the code to sort the arrival times array.
DSA C
qsort(arrival, n, sizeof(int), [1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing NULL or wrong function name to qsort.
Not defining the comparison function properly.
✗ Incorrect
The comparison function cmpfunc is used with qsort to sort integers.
3fill in blank
hardFix the error in the loop condition to find minimum platforms.
DSA C
while (i < n && j [1] n) { if (arrival[i] <= departure[j]) { platforms++; i++; } else { platforms--; j++; } if (platforms > max_platforms) max_platforms = platforms; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using greater than or equal operators causing infinite loops.
Using logical OR instead of AND.
✗ Incorrect
The loop should continue while both i and j are less than n, so the condition is i < n && j < n.
4fill in blank
hardFill both blanks to correctly compare arrival and departure times.
DSA C
if (arrival[[1]] <= departure[[2]]) { platforms++; i++; } else { platforms--; j++; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong indices causing incorrect comparisons.
Mixing up arrival and departure indices.
✗ Incorrect
We compare arrival[i] with departure[j] to decide platform count changes.
5fill in blank
hardFill all three blanks to initialize variables correctly.
DSA C
int i = [1], j = [2], platforms = [3];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting indices at 1 causing out-of-bound errors.
Initializing platforms to 1 instead of 0.
✗ Incorrect
Indices i and j start at 0, and platforms start at 0.