#! python3

"""
# We are given an unsorted array containing n numbers 
# taken from the range 1 to n. 
# The array originally contained all the numbers from 1 to n, 
# but due to a data error, one of the numbers got duplicated 
# which also resulted in one number going missing. 
# Find both these numbers.
"""

# ----------------------------------------------------
def find_corrupt_numbers(nums): 
    i = 0 
    while i < len(nums):
        j = nums[i] - 1            # this is its correct place
        if nums[i] != nums[j]:     # if it is not there
            nums[i], nums[j] = nums[j], nums[i] # swap - and keep following
        else:
            i += 1 # it is in its place - so check the next one

    for i in range(len(nums)):
        if nums[i] != i + 1:
            return [nums[i], i + 1]

    return [-1, -1]

# ----------------------------------------------------
arr = [3, 1, 2, 5, 2]
print(arr)
print(find_corrupt_numbers(arr))
