Minimize operations to restore original string by permutation
Given a string S and permutation P, both of length N. In one operation you can change the position of each and every character of the string from S[i] to S[P[i]]. Determine the minimum number of operations to restore the original string. Examples: Input: S = "ababa", P = [3, 4, 5, 2, 1] Output: 1Exp