Given an unsorted array of size n. Array elements are in range from 1 to n. One number from set {1, 2, …n} is missing and one number occurs twice in array. Find these two numbers.

Code

        public static void FindRepeatingElements(int[] input)
        {
            Console.WriteLine("input Array :" + string.Join(",", input));

            Console.Write("Repeating Elements : ");
            for (int i = 0; i < input.Length; i++)
            {
                if (input[Math.Abs(input[i]) - 1] > 0)
                {
                    input[Math.Abs(input[i]) - 1] = input[Math.Abs(input[i]) - 1] * -1;
                }
                else
                {
                    Console.Write(Math.Abs(input[i]) + ",");
                }
            }
            Console.WriteLine("");
            Console.Write("missing Elemenst : ");
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] > 0)
                {
                    Console.Write(i + 1 + ",");
                }
            }
            Console.WriteLine("");
        }
Test Case

**************************************************

Missing and Repeating Element

input Array :3,1,3

Repeating Elements : 3,

missing Elemenst : 2,

input Array :4,3,6,2,1,1

Repeating Elements : 1,

missing Elemenst : 5,

input Array :7,3,4,5,5,6,2

Repeating Elements : 5,

missing Elemenst : 1,

**************************************************