Complete the code to sort activities by their finish time.
activities.sort_by_key(|activity| activity.[1]);We sort activities by their finish time to select the maximum number of non-overlapping activities.
Complete the code to initialize the first selected activity index.
let mut last_selected = [1];The first selected activity is at index 0 after sorting by finish time.
Fix the error in the condition to check if the current activity can be selected.
if activities[i].start >= activities[[1]].finish {
We compare the start time of the current activity with the finish time of the last selected activity.
Fill both blanks to add the current activity to the selected list and update the last selected index.
selected.push(activities[[1]].clone()); last_selected = [2];
We add the current activity at index i and update last_selected to i.
Fill all three blanks to complete the activity selection loop.
for [1] in 1..activities.len() { if activities[[2]].start >= activities[last_selected].finish { selected.push(activities[[3]].clone()); last_selected = [3]; } }
The loop variable is i, used to check and select activities starting from index 1.
