3680. Generate Schedule Medium
1/**
2 * [3680] Generate Schedule
3 *
4 * You are given an integer n representing n teams. You are asked to generate a schedule such that:
5 *
6 * Each team plays every other team exactly twice: once at home and once away.
7 * There is exactly one match per day; the schedule is a list of consecutive days and schedule[i] is the match on day i.
8 * No team plays on consecutive days.
9 *
10 * 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.
11 * If no schedule exists that meets the conditions, return an empty array.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">n = 3</span>
16 * Output: <span class="example-io">[]</span>
17 * Explanation:
18 * Since each team plays every other team exactly twice, a total of 6 matches need to be played: [0,1],[0,2],[1,2],[1,0],[2,0],[2,1].
19 * It's not possible to create a schedule without at least one team playing consecutive days.
20 * </div>
21 * <strong class="example">Example 2:
22 * <div class="example-block">
23 * Input: <span class="example-io">n = 5</span>
24 * Output: <span class="example-io">[[0,1],[2,3],[0,4],[1,2],[3,4],[0,2],[1,3],[2,4],[0,3],[1,4],[2,0],[3,1],[4,0],[2,1],[4,3],[1,0],[3,2],[4,1],[3,0],[4,2]]</span>
25 * Explanation:
26 * Since each team plays every other team exactly twice, a total of 20 matches need to be played.
27 * The output shows one of the schedules that meet the conditions. No team plays on consecutive days.
28 * </div>
29 *
30 * Constraints:
31 *
32 * 2 <= n <= 50
33 *
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/generate-schedule/
38// discuss: https://leetcode.com/problems/generate-schedule/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43 pub fn generate_schedule(n: i32) -> Vec<Vec<i32>> {
44 vec![]
45 }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52 use super::*;
53
54 #[test]
55 fn test_3680() {
56 }
57}
58Back
© 2026 bowen.ge All Rights Reserved.