loading...

re: Algorithm Problem: First Duplicate in Array VIEW POST

FULL DISCUSSION
 

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).

code of conduct - report abuse