I was doing an assessment online to return the lowest positive value of an int not in the array.
I used this code:
class Solution
{
public static int solution(int[] A)
{
int hold = 1;
while (A.Contains(hold))
{
hold++;
}
return hold;
}
}
It works and received 100% for correctness however got 25% for efficiency. How can I make this more efficient? The website states that the testing can be of an array up to 100,000 values. My coding skills outside of WinForms are lacking and I would appreciate any help in order to make my code more efficient.
An example test would be [1, 3, 6, 4, 1, 2]
, and it would return 5
.