We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Agreed , as all the above built-in functions [ConvertAll(),Min,Max] are internally using loops. they are sugar coated functions for developer.
Below is my solution for uses 2 reasonable loops and print the result as expected. kindly suggest if we can improve further the below code.
long min = 0;
long max = 0;
var isFirstloop = true;
for (int i = 0; i < arr.Count; i++)
{
long tempCount = 0;
for (int j = 0; j < arr.Count; j++)
{
if (i != j)
{
tempCount += arr[j];
}
}
if (isFirstloop)
{
min = tempCount;
max = tempCount;
isFirstloop = false;
}
else
{
if (tempCount < min)
{
min = tempCount;
}
else if (tempCount > max)
{
max = tempCount;
}
}
}
Console.WriteLine($"{min} {max}");
Console.ReadKey();
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Mini-Max Sum
You are viewing a single comment's thread. Return to all comments →
Agreed , as all the above built-in functions [ConvertAll(),Min,Max] are internally using loops. they are sugar coated functions for developer.
Below is my solution for uses 2 reasonable loops and print the result as expected. kindly suggest if we can improve further the below code.