VOOZH about

URL: https://www.geeksforgeeks.org/dsa/minimum-number-of-days-required-to-schedule-all-exams/

⇱ Minimum number of days required to schedule all exams - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Minimum number of days required to schedule all exams

Last Updated : 3 Feb, 2026

Given a graph consisting of N nodes, where each node represents an exam and a 2D array Edges[][2] such that each pair of the exam (Edges[i][0], Edges[i][1]) denotes the edge between them, the task is to find the minimum number of days required to schedule all the exams such that no two exams connected via an edge are scheduled on the same day.

Examples:

Input: N = 5, E = 10, Edges[][] = {{0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 2}, {1, 3}, {1, 4}, {2, 3}, {2, 4}, {3, 4}}
Output: 5
Explanation:

👁 Image

In the above graph, all the nodes (representing exams) are connected to each other via a directed path. Therefore, the minimum number of days required to complete the exam is 5.

Input: N = 7, E = 12, Edges[][] = [{0, 1}, {0, 3}, {0, 4}, {0, 6}, {1, 2}, {1, 4}, {1, 6}, {2, 5}, {2, 6}, {3, 4}, {3, 5}, {4, 5}]
Output: 4

[Approach] Inclusion-Exclusion algorithm

To find the absolute minimum number of days, we use the Inclusion-Exclusion Principle to calculate the Chromatic Polynomial. We first use Sum Over Subsets (SOS) DP in O(V x 2^V) to count how many independent sets exist within every possible vertex subset. Finally, we check increasing values of k until the formula yields a non-zero number of valid colorings, guaranteeing the Chromatic Number is found.

Below is the implementation of the above approach:


Output
4

Time Complexity: O(2^N + N) 
Auxiliary Space: O(2^N)

Comment