Find the minimum unused value greater than MIN and smaller than MAX of the array. A negative value in the array marks the end of the list of values

int ComputeMinimumUnusedValue(int *TestArray)
{
    int FirstValue = 0;

    //TODO: Write function that computes minimum unused value > Min and < Max of the array. A negative value in the array marks the end of the list of values.

    return(FirstValue);
}

//int TestArray[] = { 5, 87, 30, 145, 241, 245, 110, -1 }; => answer is 6

I have this to do for school and I am trying to do it in O(n). I cannot use any lib. I have been trying for hours different solutions, but I can't do it.

Any of you have any idea?