The Wrong Finish Time
This is meant to be earliest-finish interval scheduling. The classes arrive already sorted by finish time.
int schedule(const vector<int>& start, const vector<int>& finish) {
int n = start.size();
int count = 1; // class 0 is always taken
for (int i = 1; i < n; i++) {
if (start[i] >= finish[i - 1]) // compare against the previous class
count++;
}
return count;
}
Which input makes it return fewer classes than the optimum? Each input is a list of (start, finish) pairs, already sorted by finish.
Sign in to answer questions and track your progress
Sign In