Skip to content

Instantly share code, notes, and snippets.

@mgonzales3
Created July 17, 2018 06:32
Show Gist options
  • Save mgonzales3/16f9946383dbafd21bee8244f2073fd5 to your computer and use it in GitHub Desktop.
Save mgonzales3/16f9946383dbafd21bee8244f2073fd5 to your computer and use it in GitHub Desktop.
minMax
static void minMax(int[] arr)
{
List<int> nbrs = new List<int>();
List<long> result = new List<long>();
foreach (int i in arr)
nbrs.Add(i);
nbrs.Sort();
for (int i = 0; i < 5; i++)
{
result.Add(addNbrs(i, nbrs));
}
result.Sort();
Console.WriteLine(result.First());
Console.WriteLine(result.Last());
}
static long addNbrs(int index, List<int> nbrs)
{
long mret = 0;
List<long> newNbrs = new List<long>();
foreach (int i in nbrs)
{
newNbrs.Add(i);
}
newNbrs.RemoveAt(index);
mret = newNbrs.Sum();
return mret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment