The calendar for scheduling is determined by the input: it runs from day 1 up to the latest occupied date provided. For example, if the latest occupied date is 10, the calendar consists of days 1, 2, ..., 10.
You should schedule the M matches on the earliest available dates.
The output should be a sequence of all dates in the calendar range.
Unavailable dates should be represented by their number.
Available dates chosen for a match should be marked with an "X".
Available dates that are not used for a match (because M matches have already been scheduled) should be represented by their number.
If there are not enough available dates to schedule all M matches, it is impossible.
The first line contains a space-separated list of integers representing the occupied dates.
The second line contains a single integer M, representing the number of match days required.
If scheduling is possible, print a single line containing the resulting sequence of dates, separated by spaces.
If it is impossible to schedule M matches, print the string "Impossible".
Using a hash set for the occupied dates will allow for efficient O(1) lookups to check if a date is available.
2 5 6 10
4
X 2 X X 5 6 X 8 9 10
The latest occupied date is 10, so the calendar runs from day 1 to 10.
The occupied dates are {2, 5, 6, 10}.
The available dates are {1, 3, 4, 7, 8, 9}.
We need to schedule M=4 matches. We greedily pick the first 4 available dates: 1, 3, 4, and 7.
The final schedule prints all dates from 1 to 10, marking the matches with 'X'.
1 2 3 5 7 8 9 10
3
Impossible
The calendar runs from 1 to 10.
The available dates are only {4, 6}.
We need to schedule M=3 matches, but only 2 dates are available. Therefore, it is impossible.
The expected time complexity is O(N).
The list of occupied dates can contain between 0 and 1000 dates.
1 <= Occupied Date <= 1000
0 <= M <= 1000
Time limit: 1 sec