Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Contains DuplicateStep-by-Step Visualization

This problem tests your ability to use sets for efficient existence checking. It demonstrates how choosing the right data structure can drastically reduce time complexity.

Problem Statement

Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.

Approach

We use a Hash Set to keep track of the elements we have seen so far. As we iterate through the array, we check if the current number is already in the set. If it is, we define it as a duplicate and return true. If we finish the loop without finding duplicates, we return false.

Time & Space Complexity

Time complexity is O(n) because we do a single pass over the array. Set lookups are O(1) on average. Space complexity is O(n) to store the elements in the set.

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.