Official algorithmic problem description and constraints.
Chef likes to create disturbance in numbers. In other words, he does not like when numbers are in their right positions.
He has a permutation P of size N. In one operation, he can swap any two adjacent elements.
His goal is to alter the permutation in such a way that Pi not equal to i satisfies for all 1≤i≤N.
Help Chef find the minimum number of operations required to reach his goal.
Note that a permutation of size N is a sequence of integers consisting of all integers from 1 to N exactly once.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.