Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to sort the arrival times vector.
DSA Rust
arrivals.sort_by(|a, b| a.[1]b);Attempts:
3 left
💡 Hint
Common Mistakes
Using eq or ne which return booleans, not ordering.
Using partial_cmp which returns Option.
✗ Incorrect
The method cmp is used to compare two values for sorting in Rust.
2fill in blank
mediumComplete the code to increment the platform count when a train arrives.
DSA Rust
if arrivals[i] <= departures[j] { platforms_needed[1]; i += 1; }
Attempts:
3 left
💡 Hint
Common Mistakes
Decrementing platforms_needed instead of incrementing.
Assigning platforms_needed to 1 instead of incrementing.
✗ Incorrect
When a train arrives before the earliest departure, we need one more platform, so increment by 1.
3fill in blank
hardFix the error in updating max_platforms when platforms_needed changes.
DSA Rust
if platforms_needed [1] max_platforms { max_platforms = platforms_needed; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using < or <= which would update max_platforms incorrectly.
Using >= which updates max_platforms even when equal.
✗ Incorrect
We update max_platforms only if platforms_needed is greater than current max_platforms.
4fill in blank
hardFill both blanks to correctly handle train departure and decrement platform count.
DSA Rust
else { platforms_needed [1]; j [2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Incrementing platforms_needed on departure.
Decrementing j instead of incrementing.
✗ Incorrect
When a train departs, we reduce platforms_needed by 1 and move to next departure by incrementing j.
5fill in blank
hardFill all three blanks to complete the loop that calculates minimum platforms.
DSA Rust
while i < arrivals.len() && j < departures.len() { if arrivals[i] [1] departures[j] { platforms_needed [2]; i += 1; } else { platforms_needed [3]; j += 1; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of <= for comparison.
Mixing increment and decrement operators.
✗ Incorrect
If arrival is less or equal to departure, increment platforms_needed; else decrement it.
