Count Failed Executions
Hello! This problem is identified as a duplcate of Count Inaccurate Results (This is a text button)
In an Amazon computing environment, there is a critical sequence of n processes that must be executed in a specific order for accurate results. The process order is represented by the array requiredSequence, where requiredSequence[i] (1 ≤ i ≤ n) denotes the process to be executed at the i-th position. Accurate results require the execution of all preceding processes.
Facing a challenge, an individual guided by the array actualSequence mistakenly runs the processes in a different order, where actualSequence[i] (1 ≤ i ≤ n) signifies the process executed at the i-th position. Both requiredSequence and actualSequence are permutations of size n.
Determine the count of processes that fail to produce accurate results due to the deviation from the specified order.
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once, for example [3, 2, 1] is a permutation while [1, 2, 1] is not.
Complete the function countFailedExecutions in the editor.
countFailedExecutions has the following parameters:
int requiredSequence[n]: order in which the processes should be executedint actualSequence[n]: order in which the processes were actually executed
Returns
int: the count of processes that fail to produce accurate results due to the deviation from the specified order
1Example 1
requiredSequence and actualSequence is that process 4 is executed first after all other processes, while the order of the remaining processes remains unchanged.
Additionally, processes 2, 3, 5, 1, and 6 rely on process 4 to produce accurate results.
However, since process 4 is executed after these processes, none of them yield accurate results.
Process 4, which does not depend on any other process for successful execution, still produces correct results.
As a result, the number of processes yielding inaccurate results is 5.2Example 2
actualSequence matches that of requiredSequence. Therefore, every process gives accurate results.
Hence, 0 processes give inaccurate results, and we return that.3Example 3
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 2*10^51 ≤ requiredSequence[i], actualSequence[i] ≤ nrequiredSequenceandactualSequenceare permutations of integers from1ton