You are given an array of distinct integers. You will take index as input and have to find out minimum number of swaps that you have to make so that all the numbers left to will be less than the value at index and all the numbers right to will be greater than the value at index .
First you will take an integer () as input. Here, denotes the total number of elements in the array. Then you will take numbers as input to your array (). Next, you will take an integer () as input. Here, denotes the total number of queries. Finally, for each query, you will take the index (; first index of the array is considered as 1 instead of 0) as input and compute the minimum number of swaps.
For each query, you have to print the minimum number of swaps.
3 3 2 1 1 2
7 3 1 2 5 6 7 4 1 4
In this sample test, you should swap (, ).
That will give you the sequence .
Now, all the values left of index 4, are smaller than the value in it and all the values in the right are larger.
Login to submit