Back to course home
0% completed
Vote For New Content
Computing plan
pratiksh.patel91
Mar 20, 2024
Computing plan
Brute Force: Compare each element with every other element in the array. If any two elements are equal, return true. Time complexity: O(n^2), space complexity: O(1).
Sorting: Sort the array and check if adjacent elements are equal. Time complexity: O(n log n) due to sorting, space complexity: O(1).
Hash Set: Use a HashSet to store unique elements. If adding an element fails (because it’s already in the set), return true. Otherwise, return false. Time complexity: O(n) for the loop, space complexity: O(n) for the HashSet.
0
0
Comments
Comments
On this page
Problem Statement
Examples
Try it yourself