Answer the question
In order to leave comments, you need to log in
Why doesn't the algorithm work?
I need the smallest unused array element let's say {0,1,2,3,5}, UniqueElement = 4
why doesn't ids.Any(d => ids[i] + 1 == ids[i + 1]) work
public static int NextId(int[] ids)
{
int UniqueElement = 0;
for (int i = 0; i < ids.Length; i++)
{
for (int j = i + 1; j < ids.Length; j++)
{
if (ids[i] == ids[j])
return 0;
if (ids.Any(d => ids[i] + 1 == ids[i + 1]))
{
UniqueElement = ids[i] + 1;
}
else
{
return ids.Max() + 1;
}
}
}
return UniqueElement;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question