End Sorted solution codechef
End Sorted solution codechef Chef considers a permutation PP of {1,2,3,…,N}{1,2,3,…,N} End Sorted if and only if P1=1P1=1 and PN=NPN=N. Chef is given a permutation PP. In one operation Chef can choose any index i (1≤i≤N−1)i (1≤i≤N−1) and swap PiPi and Pi+1Pi+1. Determine the minimum number of operations required by Chef to make the permutation PP End Sorted. Note: An array PP is said to be a permutation of {1,2,3,…,N}{1,2,3,…,N} if PP contains each element of {1,2,3,…,N}{1,2,3,…,N} exactly once. Input Format The …