Sorry, as for the time-complexity - you check for the element in hash-set. How exactly does this happen? Won't all the has set elements be checked against to check if a number is in there or not? then the time complexity will be n square?
isn't the time complexity n logn because it takes n to traverse through the array and for each element it might take log n to insert in hash set? or am I confusing with hash map?
i have a doubt. the contains method of hashset also has a time complexity of O(n) and then there is for loop as well so shouldnt the time complexity be O(n^2). Is it the same as brute force approach?
@@nikoo28 you are right we cant say it will improve the algorithm, can we say its one of the solutions? If I find the entry in map I can say there is a duplicate
Another Method that we can sort the array and check its neighbor values.
Arrays.sort(nums);
for(int i=1;i
Due to sorting, the time complexity will be O(nlogn). And using a HashSet will do it in O(n)
Really Great explanation👍.Thank you 😊
Superb explanation. Thank you
such a great explanation, thank you mate
thank you so much bhaiya for such a great explaination.
Keep watching
Simple and lucid explaination
Your explanation is so good
Great explanation and amazing content sir
Glad I could help :)
Sorry, as for the time-complexity - you check for the element in hash-set. How exactly does this happen? Won't all the has set elements be checked against to check if a number is in there or not? then the time complexity will be n square?
Checking in HashSet happens in O(1) time
isn't the time complexity n logn because it takes n to traverse through the array and for each element it might take log n to insert in hash set?
or am I confusing with hash map?
Hashset insert takes place in O(1)
i have a doubt. the contains method of hashset also has a time complexity of O(n) and then there is for loop as well so shouldnt the time complexity be O(n^2). Is it the same as brute force approach?
Contains method works in O(1)
@nikoo28 thanks for replying back. But how is it O(1) cuz it will search through the whole set right?
We could have avoided the contains check. add() will return false if the number is already present!!
Why are we using a HashSet and not a HashMap Nikhil ??
what advantage would a hashmap give you?
@@nikoo28 you are right we cant say it will improve the algorithm, can we say its one of the solutions? If I find the entry in map I can say there is a duplicate
very nice
Super ❤️
for (int n : nums) {
if(!set.add(n)) {
return true;
}
}
GREAT
Bro it is tricky in c
what part are you facing a problem with?
simply explain ..