educative.io

What does return - 1 do?

what does return - 1 do?

I suppose you are talking about the solution in this lesson https://www.educative.io/courses/data-structures-coding-interviews-java/m274vRXDnMp.

The function is supposed to return an index of the first unique element which is a positive number. But in a case where the array does not contain any unique number at all, we return a negative number to differentiate between valid indices and this specific case.
If you are confused about the space between - and 1 I think it’s a typo.