The question says that for some K iterations, one array value needs to be swapped with another array value in A. However the example does two swaps in one of the steps. Here indicated in red:
Without this additional swapping, the solution would be:Initial position: (0,1,2,3,4)
Step 1 - Reverse A[1] to A[1]: (0,1,2,3,4)
Step 2 - Reverse A[2] to A[3]: (0,1,3,2,4)
Step 3 - Reverse A[0] to A[3]: (2,3,1,0,4)
Step 4 - Reverse A[3] to A[1]: (2,0,1,3,4)
R(5,4)=0×2+1×0+2×1+3×3+4×4=27
R(5,4)=0×2+1×0+2×3+3×1+4×4=25
In don't understand why this is happening, is there an error in the explanation or have i misinterpreted the question here. Hope someone knows!
Thanks in Advance