3
long long taskSchedulerII(vector<int> &tasks, int space) {4
// Use a map to keep track of the last occurrence day for each task5
unordered_map<int, long long> lastOccurrence;7
// Initialize the current day to 08
long long currentDay = 0;10
// Loop through each task in the list11
for (int task : tasks) {12
// If the task has been executed before13
if (lastOccurrence.find(task) != lastOccurrence.end()) {14
// Check if the space constraint is satisfied15
if (currentDay - lastOccurrence[task] <= space) {16
// If not, move the currentDay ahead17
currentDay = lastOccurrence[task] + space + 1;19
// If yes, just increment the current day23
// If the task hasn't been executed before, simply increment the current28
// Update the last occurrence of the task29
lastOccurrence[task] = currentDay;