Permutation Operations π»
A permutation of n numbers is a sequence where each number from 1 to n appears exactly once. For a given permutation p and any arbitrary array arr, a permutation operation is defined as
i (1 ≤ i ≤ n) temp_arr[i] = arr[p[i]]arr = temp_arr
Given a permutation p of n numbers, start with any arbitrary array arr of n distinct elements and find out the minimum number of permutation operations (at least 1) needed in order to reach the original array. Since the answer can be quite large, return the answer modulo 10^9+7.
Complete the function countOperations in the editor.
countOperations has the following parameter:
int p[n]: a permutation of the integers from1ton
Returns
int: the number of operations required modulo 109 + 7
1Example 1
n = 3. Taking any arbitrary array arr = [7, 8, 9]
arr, the resulting array is [7, 9, 8].[7, 8, 9].Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 1051 ≤ p[i] ≤ n