Answer to Question #82321 in C# for vikas
static int MinDistance(int a, int idx)
if (idx < 0 || idx >= a.Length)
throw new Exception("The index is outside the array");
int d = -2;
for (int i = 0; i < a.Length; i++)
if ((a[i] == (a[idx] + 1) || a[i] == (a[idx] - 1)) && i != idx)
d = Math.Abs(idx - i);
if (d > 100000000)
int a - the array in which we look for the distance;
int idx - index of the element for which we are looking for adjacent values.
Need a fast expert's response?Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!