Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Iterate through the array, adding each element to a Set. Before adding, check if the element already exists in the Set. If it does, a duplicate has been found. If the loop completes without finding a duplicate, return false.
A Set provides O(1) average-case insertion and membership testing. If any element is already in the Set when we try to add it, it must have appeared earlier in the array.
Updated Feb 2026