# Interval scheduling problem implementation

I am learning the Interval scheduling problem, and I came up after some reading with an implementation. I'll list my steps and the code, please let me know if this is correct or there is a more optimise way.

Problem: I have one resource and a list of tasks. The goal is execute these tasks in a way that makes the number of tasks waiting to be executed minimal.

Algorithm:

1. Create two sets of tasks. A is the set of tasks. B is a set of incompatible tasks.

2. Initiate A with all tasks that you have at the beginning of the solution.

3. pick up from A the soonest to finish task, let's call it T.

4. remove from A all the incompatible tasks to T and put them in B.

5. go back to step number 3 and repeat until A is empty.

6. Move all tasks from B to A.

7. Go back to step number 3.

8. Go back to step number 6 until B is empty.

Implementations:

I chose Map data structure to represents both A and B because look up is of O(1).

import java.sql.Timestamp;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;

public class First {
public static void main(String[] args) {
Timestamp.from(Instant.parse("2020-07-25T08:00:00.000Z")),
Timestamp.from(Instant.parse("2020-07-25T09:00:00.000Z"))));
, Timestamp.from(Instant.parse("2020-07-25T09:00:00.000Z"))
, Timestamp.from(Instant.parse("2020-07-25T10:00:00.000Z"))));
Timestamp.from(Instant.parse("2020-07-25T09:30:00.000Z")),
Timestamp.from(Instant.parse("2020-07-25T10:30:00.000Z"))));
results.stream()
System.out.println(String.format("Task %d:%s starts at %s, ends at %s",
});
}

/**
* 1- pick up the next one.
* 2- remove all none compatible tasks.
* 3- repeat.
*
* @param resource
* @return
*/
return solve(map, new HashMap<>(), resource);
}

Resource resource) {
} else {
}
} else {
return results;
}
}

while (iterator.hasNext()) {
int id = iterator.next();
}
}
return results;
}

if (map == null || map.isEmpty()) {
throw new RuntimeException("Shouldn't be called on an empty input.");
}
Iterator<Integer> iterator = map.keySet().iterator();
while (iterator.hasNext()) {
int id = iterator.next();
if (result == null) {
result = map.get(id);
} else {
}
}
}
return result;
}
}


@Value