Programming Geek
Rated 4.1/5 based on 446 reviews

### ISL Schedule: TCS CodeVita 2016 Question

Problem : ISL Schedule

The Indian Soccer League (ISL) is an annual football tournament.
The group stage of ISL features N teams playing against each other with following set of rules:
1. N teams play against each other twice - once at Home and once Away
2. A team can play only one match per day
3. A team cannot play matches on consecutive days
4. A team cannot play more than two back to back Home or Away matches
5. Number of matches in a day has following constraints
• The match pattern that needs to be followed is -
• Day 1 has two matches and Day 2 has one match,
• Day 3 has two matches and Day 4 has one match and so on
• There can never be 3 or more matches in a day
6. Gap between two successive matches of a team cannot exceed floor(N/2) days where floor is the mathematical function floor()
7. Derby Matches (any one)
• At least half of the derby matches should be on weekend
• At least half of the weekend matches should be derby matches

Input Format:

First line contains number of teams (N).
Next line contains state ID of teams, delimited by space
Output Format:

Match format: Ta-vs-Tb
where Ta is the home team with id a and Tb is the away team with id b.
For each day print the match(es) in following format:-
• Two matches:- "#D Ta-vs-Tb Tm-vs-Tn"
• One match:- "#D Tx-vs-Ty"
where D is the day id and [a, b, m, n, x, y] are team ids.

Constraints:
1. 8 <= N <= 100
Note :
• Team ids are unique and have value between 1 to N
• Day id starts with 1
• Every 6th and 7th day are weekends
• Derby is a football match between two teams from the same state

Sample Input and Output

SNo.InputOutput
1
8
1 2 5 4 3 1 6 6

#1 T1-vs-T6 T3-vs-T5
#2 T7-vs-T4
#3... and so on

Note:- There can be multiple correct answers for the same test cases. For better understanding of test case refer this
PDF. This PDF contains one of the correct answer for a test case.

Explanation:

There are 8 teams with following information:-

 Team ID 1 2 3 4 5 6 7 8 State ID 1 2 5 4 3 1 6 6