I'm having a integer array of 10 Million elements, how to write a function in C# which returns True if the array has a pair which sums up to 75.
My code is:
int sum = 75, max = 10000000;
int[] array = new int[max];
bool checkFlag = false;
Random rnd = new Random();
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < max; i++)
{
array[i] = rnd.Next(0, max * 20);
}
Array.Sort(array);
if (array[0] + array[1] <= sum)
{
Console.WriteLine("{0} + {1} = {2}", array[0], array[1], array[0] + array[1]);
checkFlag = true;
}
Console.WriteLine("Sum upto 75 is: " + checkFlag);