AO
Back

Count Process Schedules with No Consecutive Repeats

OAAsync OALast reported December 2025Low Frequency

Problem Overview

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.

What is settled

  • Every interval runs exactly one of the n_processes processes.
  • A process may run again later, just not in the interval right after its own.
  • Return the count modulo 10^9 + 7.

Not reported (state your assumption)

  • Input sizes. Neither report gives a range for n_processes or n_intervals.
  • The value for n_intervals = 0.
  • An example with its answer. Neither report posts one; the examples below are ours.
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 Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
DFS over the intervalsThe 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.

Practice

Write your own against 9 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Citadel with friends?

Send them this page. It is free to read, no account needed.

More Citadel Questions

Free preview

Every question in the Citadel catalog gets this depth

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.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Citadel · OA · Reported 2× across candidate reports
Is this helpful?