Process Scheduling
Learn this problemProblem 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) → intComplete the function processScheduling in the editor with the following parameters:
n_intervals: the number of time intervalsn_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 = 2The 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.