Complete the code to select the next interval with the earliest finish time.
intervals.sort_by_key(|interval| interval.[1]);Sorting intervals by their end time helps the greedy algorithm pick the interval that finishes earliest, allowing more intervals to fit later.
Complete the code to check if the current interval can be added without overlapping.
if intervals[i].start >= [1] { selected.push(intervals[i]); last_end = intervals[i].end; }
We compare the start of the current interval with the end time of the last selected interval to avoid overlaps.
Fix the error in the greedy coin change algorithm that fails for some coin sets.
let mut amount = [1]; let mut coins_used = 0;
The variable 'amount' should start with the total amount to change, not zero or coin count.
Fill both blanks to complete the greedy interval scheduling loop.
for i in 1..intervals.len() { if intervals[i].[1] >= [2] { selected.push(intervals[i]); last_end = intervals[i].end; } }
We check if the start of the current interval is after or equal to the end of the last selected interval to avoid overlap.
Fill all three blanks to complete the greedy coin change selection.
while amount > 0 { let coin = coins[[1]]; if coin <= amount { amount -= coin; coins_used += [2]; } else { [3]; } }
We use 'index' to track the current coin, add one coin when used, and move to next coin when current coin is too big.
