Last Updated: 15 Oct, 2025

Tennis Match Scheduling

Moderate

Problem statement

You are an organizer for a company's tennis club. Given a list of dates where participants are unavailable, and a required number of matches M, your task is to schedule the matches on the available days.


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.


Input Format:
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.


Output Format:
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".


Note:
Using a hash set for the occupied dates will allow for efficient O(1) lookups to check if a date is available.