Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
mil o
[JS] Why not create a set and compare the size to the array.length?

mil o

Dec 16, 2024

Is there a reason why this would not be a good solution? Maybe I am overlooking something here

const uniqueSet = new Set(nums); if (uniqueSet.size !== nums.length) { return true; }

1

0

Comments
Comments
Andre Abtahi
Andre Abtahi9 months ago

that's what i would have done!

H
heliamarasinghe 4 months ago

This is exactly what I did since we dont need to know that numbers are duplicating

On this page

Problem Statement

Examples

Solution

Approach 1: Brute Force

Approach 2: Using Hash Set

Approach 3: Sorting