You are given two arrays and of size . Your task is to sort array A (non-decreasing) by using the following operation for the minimum number of times.
Operation steps are:
If there is a way to sort array using the above operation, then find the minimum number of operations that must be performed. If it is impossible to sort the array, then print -1.
Input format
Output format
For each test case, print a single line indicating the minimum number of operations if sorting can be done. If it is not possible to sort the array, print -1.
Constraints
First test case:
The array A is already sorted, so we don't need to perform any operation.
Second test case:
The array A is initially not sorted, A={8,7} and B={7,8}, we need to perform operation. We have no other choice than choosing index as 1, according to operation we need to swap A1 and B2 and swap A2 and B1 , after performing array A={8,7} and B={7,8} remains the same and we have no other options, so it is impossible to sort the array.
Third test case:
A={2,3,2} and B={2,1,2} and let us choose i=1, according to operation we need to swap A1 and B2 and swap A2 and B1 , after performing array A={1,2,2} and B={3,2,2} and now note that array A is sorted. Number of operations in this case are 1.