Arrays and Hashing Hash map lookups

59. Contains Duplicate

Easy 147 DSA Sheet

You are given an array of integers nums. Return true if some value appears in it at least twice, and false if every value in it is different.

The two copies of a value can be anywhere in the array. They do not have to be next to each other.

Example 1

Input: nums = [4, -7, 12, 0, -7, 9]

Output: true

Explanation: The value -7 appears at index 1 and again at index 4. One value that appears twice is enough for true.

Example 2

Input: nums = [8, 3, -2, 15, 6]

Output: false

Explanation: All five values are different, so no value appears twice.

Example 3

Input: nums = [-1000000000, 1000000000, -1000000000]

Output: true

Explanation: The smallest value allowed appears at both ends of the array. The value between the two copies does not matter.

Check your understanding

Work out the answer for this input before you write any code.

nums = [5, -5, 3]

Constraints

  • 1 ≤ nums.length ≤ 105
  • -109 ≤ nums[i] ≤ 109

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.