Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the arrival times list.
DSA Python
arrivals = [900, 940, 950, 1100, 1500, 1800] arrivals.[1]()
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() instead of sort()
Using pop() which removes elements
Using reverse() which reverses order but does not sort
✗ Incorrect
We use the sort() method to arrange arrival times in increasing order.
2fill in blank
mediumComplete the code to initialize the platform count to zero.
DSA Python
platforms = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Starting count from 1 instead of 0
Using None which is not a number
Using negative numbers which don't make sense here
✗ Incorrect
We start counting platforms from zero before processing trains.
3fill in blank
hardFix the error in the loop to iterate over the arrival times correctly.
DSA Python
for i in [1](len(arrivals)): print(arrivals[i])
Attempts:
3 left
💡 Hint
Common Mistakes
Using list(len(arrivals)) which causes error
Using arrivals directly which gives values, not indices
Using enumerate which returns pairs, not just indices
✗ Incorrect
We use range(len(arrivals)) to get indices from 0 to length-1.
4fill in blank
hardFill both blanks to check if a train departs before the next arrives.
DSA Python
if departures[i] [1] arrivals[i + 1]: platforms [2] 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<=' in comparison
Using '-=' which decreases platforms incorrectly
✗ Incorrect
We check if departure is before or at arrival, then increase platforms.
5fill in blank
hardFill both blanks to create a dictionary of trains with arrival times greater than 1000.
DSA Python
result = {train: arrival for train, arrival in schedule.items() if arrival [1] 1000 and train [2] 'Express'}Attempts:
3 left
💡 Hint
Common Mistakes
Using ',' instead of ':' in dictionary comprehension
Using '<' instead of '>' for arrival time check
Using '==' instead of '!=' to exclude train
✗ Incorrect
We use ':' to map train to arrival, '>' to filter times after 1000, and '!=' to exclude 'Express'.
