You can push elements into a Set and check to see if it exists already when while iterating. If it exists, then you can terminate and return the index of the repeated element. This should run in O(n) time (disregarding Set resizing).
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.