Contains Duplicate

Try to solve the Contains Duplicate problem.

Statement#

For a given array of integers, nums, return TRUE if it contains duplicates. Otherwise, return FALSE.

Constraints:

  • 11 \leq nums.length 103\leq 10^3

  • 109-10^9 \leq nums[i] 109\leq 10^9

Examples#

Created with Fabric.js 3.6.6

1 of 2

Created with Fabric.js 3.6.6

2 of 2

Understand the problem#

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Contains Duplicate

1

Select the correct option if the following array is passed as input:

nums = [2, 2, 3, 1, 2]

A)

TRUE

B)

FALSE

Question 1 of 30 attempted

Try it yourself#

Implement your solution in the following coding playground:

The optimal solution to this problem runs in O(n) time and takes O(n) space.

Python
usercode > main.py
Input #1
%0 node_01 1 node_11 3 node_21 6 node_31 2 node_41 3 node_51 5 node_61 4 node_71 8 node_81 7 node_91 6 node_101 2 node_111 3 node_121 5 node_131 2 node_141 9 node_151 4 node_161 3
Visualization for Input #1
Contains Duplicate

You might want to go over the Knowing What To Track pattern again.

Solution: Valid Anagram

Solution: Contains Duplicate