You are correct in observing that the array is not fully sorted, but this behavior is intentional and acceptable for the specific task of finding the corrupted pair (one duplicated and one missing number). The goal of this algorithm is to find a pair of numbers where one is duplicated and the other is missing in a given array. It is not necessarily to sort the array. The cyclic sort in this algorithm is used to place numbers in their correct positions as much as possible, which is sufficient to identify the corrupted pair without needing to fully sort the array.
Despite not fully sorting the array, the algorithm efficiently identifies the corrupted pair with a time complexity of O(n), which is optimal for this problem.
I hope this helps in understanding why complete sorting is not applicable for this problem. Feel free to share further suggestions and feedback. We’d be happy to help. Thanks!