CodeSpeek

Contains Duplicate

Easy · Arrays & Hashing

Given an array of integers, determine whether any value appears at least twice in the array. Return true if there is at least one duplicate value, and false if every element is distinct.

Examples

Input:  nums = [1,2,3,1]
Output: true
Why:    The value 1 appears twice.
Input:  nums = [1,2,3,4]
Output: false
Why:    All elements are distinct.
Input:  nums = [1,1,1,3,3,4,3,2,4,2]
Output: true

Constraints

1 <= nums.length <= 100000, -1000000000 <= nums[i] <= 1000000000

Practise it by voice

Describe the solution out loud and the interviewer writes exactly what you say, asks when you are vague, and runs the tests in your browser.

Practise Contains Duplicate

This statement is written for CodeSpeek. The problem is part of the NeetCode 150 list; Watch NeetCode's explanation of Contains Duplicate. Reference solutions from the NeetCode repository (MIT) are used to verify our tests.