def count_schedules(n_processes: int, n_intervals: int) -> int:
Assign processes to time intervals so that no process runs in two consecutive intervals, and count the valid assignments.
The fuller of two reports gives the prompt in English, framed as Grace Hopper's process-synchronization algorithm; the core of it, verbatim:
She designed an algorithm where one process cannot occupy consecutive time slots. To evaluate the performance of this algorithm, Hopper needed to determine the number of ways to allocate n_processes in n_intervals different time intervals according to this rule. Since the number of ways can be very large, return the result modulo (10⁹ + 7).
The second report states it more plainly: you have n processes to assign to n_intervals time intervals; each time point runs exactly one process, and the same process may not be assigned to two consecutive intervals. Return the number of valid assignments.
n_processes processes.n_processes or n_intervals.n_intervals = 0.count_schedules(3, 1) -> 3
count_schedules(3, 2) -> 6 (any pair of different processes, in order)
count_schedules(1, 3) -> 0 (one process cannot fill consecutive intervals)
Both reports are Citadel online assessments with two problems in 75 minutes, for new-grad and campus software engineering roles; the campus one (December 2025) names HackerRank. This problem was paired with the palindrome-password problem in one and the largest-team problem in the other. One report gives the full prompt and three ways to solve it: a DFS over the intervals, the closed form n·(n−1)^(m−1), and a DP over (interval, process). Neither report gives an example, input sizes, or how the poster did.
Assign processes to time intervals so that no process runs in two consecutive intervals, and count the valid assignments.
The fuller of two reports gives the prompt in English, framed as Grace Hopper's process-synchronization algorithm; the core of it, verbatim:
She designed an algorithm where one process cannot occupy consecutive time slots. To evaluate the performance of this algorithm, Hopper needed to determine the number of ways to allocate n_processes in n_intervals different time intervals according to this rule. Since the number of ways can be very large, return the result modulo (10⁹ + 7).
The second report states it more plainly: you have n processes to assign to n_intervals time intervals; each time point runs exactly one process, and the same process may not be assigned to two consecutive intervals. Return the number of valid assignments.
n_processes processes.n_processes or n_intervals.n_intervals = 0.count_schedules(3, 1) -> 3
count_schedules(3, 2) -> 6 (any pair of different processes, in order)
count_schedules(1, 3) -> 0 (one process cannot fill consecutive intervals)
| Approach | Notes |
|---|---|
| DFS over the intervals | The poster's first idea: n choices at the first level, n − 1 at every later one, which the poster turns into the closed form. Enumerating the tree itself is exponential (our note). |
| DP over (interval, process) | The poster's second idea: dp[i][j] = valid schedules for the first i intervals ending with process j. Our analysis: O(n·m), same count, and it extends if the rule changes. |
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.