alexb7
BAN USERpublic class MinRangeFinder
{
/*
* {1,4,7,9,10,34,48}
* {23,24,25,26,27,28,29,33,111,222}
* {7,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33}
* solution: {34,33,33}
*/
public static int[] FindMinRange(int[] a, int[] b, int[] c)
{
// keep track of the min range
int[] minRange = new int[3] { a[0], b[0], c[0] };
int minRangeValue = GetRange(a[0], b[0], c[0]);
// arrays
int[][] arrays = new int[][] { a, b, c };
int[] indices = new int[] { 0, 0, 0 };
while (TryAdvanceToNextMin(arrays, indices))
{
int rangeValue = GetRange(a[indices[0]], b[indices[1]], c[indices[2]]);
if (rangeValue < minRangeValue)
{
minRange = new int[] { a[indices[0]], b[indices[1]], c[indices[2]] };
minRangeValue = rangeValue;
}
}
return minRange;
}
private static int GetRange(int x, int y, int z)
{
return Math.Max(Math.Max(x, y), z) - Math.Min(Math.Min(x, y), z);
}
private static bool TryAdvanceToNextMin(int[][] arrays, int[] indices)
{
int arrayIndexToAdvance = -1;
int minVal = int.MaxValue;
for (int i = 0; i < arrays.Length; i++)
{
if (arrays[i].Length > indices[i] + 1)
{
if (arrays[i][indices[i] + 1] < minVal)
{
arrayIndexToAdvance = i;
minVal = arrays[i][indices[i] + 1];
}
}
}
if (arrayIndexToAdvance > -1)
{
indices[arrayIndexToAdvance]++;
return true;
}
return false;
}
}
RepElijahMiller, abc at A9
I am highly organized with exceptional commitment to task completion and quality assurance when working with computer software programs. I ...
RepBruceKeter, HTML Experienced at 247quickbookshelp
Bruce , a pediatrician studies psychoanalysis where I try to understand children's needs and family dynamics. To do more research ...
Repharveyoberion, Analyst at AMD
Hi, I am Harvey, from the USA. I am working as a soil scientist. I study soil as a natural ...
Repharrytallh, Web Developer at Realty Depot
I am working as a Web developer . Here I create and maintain websites. Here I handle many responsibilities where I ...
Repameliahill344, abc at Detail Oriented
Professionally licensed Architect with a Master’s degree in Architecture and more than 4 years experience designing commercial buildings, offices ...
RepShivelyFauver, Animator at AMD
Project Management Assistant with a proven record in developing and managing project budgets, completing presentations and reports. As nowadays astrology ...
RepEshikaLopez, general assistant at MMSS
Dedicated and reliable general assistant with background in and strong knowledge of secretarial and administrative principles. Capable of providing direct ...
- alexb7 June 21, 2013