adplus-dvertising

Array sorting CodeChef Solution

Hey Codders, Here available Array sorting CodeChef Solution

We Are Discuss About Array sorting CodeChef Solution Today

Array sorting Problem Code: ARRSORT

You are given an unsorted permutation PP of size NN. An operation is defined as:

  • Swap PiPi and Pi+KPi+K for any ii in the range [1,NK][1,N−K].

Find the maximum value of KK, such that, the permutation PP can be sorted by applying any finite number of operations.

Note that, a permutation of size NN contains all integers from 11 to NN exactly once.

Input Format

  • The first line of input will contain a single integer TT, denoting the number of test cases.
  • Each test case consists of two lines of input.
    • The first line of each test case contains an integer NN, the size of permutation.
    • The next line contains NN integers describing the permutation PP.
  • It is guaranteed that the given permutation is not sorted.

Output Format

For each test case, output on a new line the maximum possible value of KK.

Array sorting CodeChef Solution

Constraints

  • 1T1051≤T≤105
  • 2N1052≤N≤105
  • Sum of NN over all test cases does not exceed 105105.

Sample Input 1

3
4
4 2 3 1
5
1 4 3 2 5
2
2 1

Sample Output 1

3
2
1

Array sorting CodeChef Solution

Explanation

  • Test Case 11: Permutation can be sorted by swapping P1P1 and P4P4. So, the maximum possible value of KK is 33. It can be shown that we cannot sort the permutation for any K>3K>3.

  • Test Case 22: Swapping P2P2 and P4P4 will sort the permutation. So, the maximum possible value of KK is 22. It can be shown that we cannot sort the permutation for any K>2K>2.

  • Test Case 33: Swapping P1P1 and P2P2 will sort the permutation. So, the maximum possible value of KK is 11. It can be shown that we cannot sort the permutation for any K>1K>1.

SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.

If You Want To Learn Something New Then Visit Our Official Channel YOUTUBE

Related Posts

One thought on “Array sorting CodeChef Solution

Leave a Reply

Your email address will not be published.