Skip to content
EasyArraysAI interview only

Contains Duplicate

Asked atamazonapplemicrosoftgoogleadobebloomberg

01 · Problem

You are given an integer array nums. Decide whether any value occurs in the array more than once.

Return true if at least one value shows up two or more times, and false if every element is unique.

02 · Examples

Example 01
Input
nums = [1,2,3,1]
Output
true

The value 1 appears at index 0 and again at index 3.

Example 02
Input
nums = [1,2,3,4]
Output
false

All four values are different from one another.

Example 03
Input
nums = [1,1,1,3,3,4,3,2,4,2]
Output
true

Several values repeat, for example 1, 3, 4 and 2; a single repeat is enough to return true.

03 · Constraints

  • 011 <= nums.length <= 105
  • 02-109 <= nums[i] <= 109
  • 03Values may be negative, and a single-element array never contains a duplicate

04 · Optimal complexity

Time
O(n)
Space
O(n)
05 · Two ways to work on it

Practice it alone or rehearse it as an interview.

Practice Mode gives you an editor and test runs, nothing else. AI Interview Mode puts a voice interviewer on the other side, adds a clock, and ends with a scored summary of the round.