Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the arrival times slice.
DSA Go
sort.[1](arrival)Attempts:
3 left
💡 Hint
Common Mistakes
Using Reverse instead of Sort causes incorrect order.
Using Shuffle or Swap does not sort the slice.
✗ Incorrect
We use sort.Sort to sort the slice in ascending order, which is necessary to process arrival times correctly.
2fill in blank
mediumComplete the code to increment the platform count when a train arrives before the previous one departs.
DSA Go
if arrival[i] [1] departure[j] {
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < reverses the logic.
Using == or <= does not correctly identify overlapping trains.
✗ Incorrect
If the arrival time is less than the departure time, it means a new platform is needed.
3fill in blank
hardFix the error in the loop condition to avoid index out of range error.
DSA Go
for i, j := 0, 0; i < len(arrival) && j [1] len(departure); {
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes index out of range panic.
Using > or >= reverses the loop logic.
✗ Incorrect
Both i and j must be strictly less than the length of their slices to avoid out of range errors.
4fill in blank
hardFill both blanks to correctly update platform counts and indices.
DSA Go
if arrival[i] [1] departure[j] { plat_needed++ i[2] } else { plat_needed-- j++ }
Attempts:
3 left
💡 Hint
Common Mistakes
Using > instead of < reverses the condition.
Using -- instead of ++ for i causes wrong index update.
✗ Incorrect
When arrival is less than departure, we increase platform count and move to next arrival (i++).
5fill in blank
hardFill all three blanks to create a map of platform counts per time and filter times with more than one platform needed.
DSA Go
platforms := map[int]int{}
for i := 0; i < len(arrival); i++ {
platforms[[1]]++
}
result := map[int]int{t: c for t, c in platforms if c [2] [3]Attempts:
3 left
💡 Hint
Common Mistakes
Using departure[i] instead of arrival[i] counts wrong times.
Using <= or < instead of > filters incorrectly.
✗ Incorrect
We count platforms at arrival times and filter those with count greater than 1.
