# edge case, N + 1 is missing# but unlike the case below, we can immediately compute and return thisif a.length ==1return2if a==1return1if a==2end
sorted = a.sort
sorted.each_index do|index|return index +1if(sorted[index]!= index +1)
end# edge case, N + 1 is missingreturn a.length +1end
Edge cases are always tricky! Always get into the habit of asking: what can go wrong? Good questions to ask are: what about empty inputs, beginning/ending elements are missing.
I have a feeling that for the other languages, you need to implement your own sorting algorithm (like bubble sort).