Problem Statement: Given an Array of size N ,Find if it is possible to sort it in non-decreasing order by doing swaps according to following rules…