Problem · Combinatorics

Process Scheduling

Learn this problem
EasyCitadelOA

Problem statement

Grace Hopper is famously recognized as the "First Lady of Software." She played a significant role in the creation of the first all-electrical digital computer, UNIVAC (Universal Automatic Computer).

Hopper's responsibilities included developing a process synchronization solution to ensure that never-ending processes experience a bounded wait, i.e., one that never completes. 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 the algorithm. Since the number of ways can be very large, return the result modulo 10^9 + 7.

Note: All the processes are never-ending, so even if n_intervals is very large, the processes will not end.

Function

processScheduling(n_intervals: int, n_processes: int) → int

Complete the function processScheduling in the editor with the following parameters:

  • n_intervals: the number of time intervals
  • n_processes: the number of processes

Returns

int: the number of ways processes can be scheduled in time intervals modulo 10^9 + 7

Examples

Example 1

n_intervals = 3n_processes = 2return = 2

The source example shows the schedule allocation can look like {A, B, A} or {B, A, B}. These are the two valid allocations for the given inputs, so the answer is 2.

More Citadel problems

drafts saved locally
public int processScheduling(int n_intervals, int n_processes) {
  // write your code here
}
n_intervals3
n_processes2
expected2
checking account