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).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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).