Blind 75
2 / 75Free practice

Contains Duplicate

Easy · Arrays & hashing

Jump to code

Decide whether an integer array contains any repeated value. Return true when two different positions hold the same number.

Examples

Example 1

nums = [1,2,3,1]

Output: true

Example 2

nums = [1,2,3,4]

Output: false

Constraints

  • The input is an array of integers. Empty input has no duplicates.
Need a hint?

Only membership matters; the earlier position is irrelevant.

Real array interview questions

Questions on the same topic that candidates reported from real company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 11 cases. No account or XP needed for this problem.
Language
Case 1
Input
[
  [
    1,
    2,
    3,
    1
  ]
]
Expected
true
Case 2
Input
[
  [
    1,
    2,
    3,
    4
  ]
]
Expected
false
Case 3
Input
[
  [
    1,
    1,
    1,
    3,
    3,
    4,
    3,
    2,
    4,
    2
  ]
]
Expected
true
Case 4
Input
[
  [
    42
  ]
]
Expected
false
Case 5
Input
[
  [
    -1,
    -2,
    -3,
    -1
  ]
]
Expected
true

Drafts are saved per language in this browser when storage is available.