#3680

Generate Schedule

medium · 23.9% accepted · 49 likes · top 3%

array · math · greedy

⊣ practice⊣ open on leetcode ↗

Description

You are given an integer n representing n teams. You are asked to generate a schedule such that:

- Each team plays every other team exactly twice: once at home and once away.

- There is exactly one match per day; the schedule is a list of consecutive days and schedule[i] is the match on day i.

- No team plays on consecutive days.

Return a 2D integer array schedule, where schedule[i][0] represents the home team and schedule[i][1] represents the away team. If multiple schedules meet the conditions, return any one of them.

If no schedule exists that meets the conditions, return an empty array.

Solution