Contains Duplicate (LeetCode 217) | Full solution with HashSet explanation | Study Algorithms

  Рет қаралды 18,917

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 30
@pavanrajjagdale9369
@pavanrajjagdale9369 2 жыл бұрын
Really Great explanation👍.Thank you 😊
@vineeshreddy9998
@vineeshreddy9998 Жыл бұрын
Superb explanation. Thank you
@viniz0r
@viniz0r 9 ай бұрын
such a great explanation, thank you mate
@mohammedilyas8824
@mohammedilyas8824 2 жыл бұрын
Great explanation and amazing content sir
@nikoo28
@nikoo28 2 жыл бұрын
Glad I could help :)
@SanthoshaK-px8rq
@SanthoshaK-px8rq 6 ай бұрын
Another Method that we can sort the array and check its neighbor values. Arrays.sort(nums); for(int i=1;i
@bhavitvora9364
@bhavitvora9364 3 ай бұрын
Due to sorting, the time complexity will be O(nlogn). And using a HashSet will do it in O(n)
@vamshisundupalle6141
@vamshisundupalle6141 Жыл бұрын
Your explanation is so good
@satyamgupta6030
@satyamgupta6030 Жыл бұрын
thank you so much bhaiya for such a great explaination.
@nikoo28
@nikoo28 Жыл бұрын
Keep watching
@pranaym143
@pranaym143 2 жыл бұрын
Simple and lucid explaination
@pentainamerica
@pentainamerica 9 ай бұрын
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?
@nikoo28
@nikoo28 9 ай бұрын
Hashset insert takes place in O(1)
@lakshaysaini2070
@lakshaysaini2070 8 ай бұрын
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
@nikoo28 8 ай бұрын
Contains method works in O(1)
@lakshaysaini2070
@lakshaysaini2070 8 ай бұрын
@nikoo28 thanks for replying back. But how is it O(1) cuz it will search through the whole set right?
@karthik-varma-1579
@karthik-varma-1579 9 ай бұрын
GREAT
@jintodo6550
@jintodo6550 Жыл бұрын
very nice
@abhinavd2
@abhinavd2 2 жыл бұрын
Super ❤️
@kadirv
@kadirv 9 ай бұрын
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?
@nikoo28
@nikoo28 9 ай бұрын
Checking in HashSet happens in O(1) time
@anshumansolanki6775
@anshumansolanki6775 Жыл бұрын
Why are we using a HashSet and not a HashMap Nikhil ??
@nikoo28
@nikoo28 Жыл бұрын
what advantage would a hashmap give you?
@anshumansolanki6775
@anshumansolanki6775 Жыл бұрын
@@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
@SatishSingh-eb5tq
@SatishSingh-eb5tq 9 ай бұрын
We could have avoided the contains check. add() will return false if the number is already present!!
@rajabhowmick1342
@rajabhowmick1342 10 ай бұрын
for (int n : nums) { if(!set.add(n)) { return true; } }
@SushmaSulthan
@SushmaSulthan 11 ай бұрын
Bro it is tricky in c
@nikoo28
@nikoo28 10 ай бұрын
what part are you facing a problem with?
@Daddyboltee
@Daddyboltee 9 ай бұрын
simply explain ..
Каха и дочка
00:28
К-Media
Рет қаралды 3,4 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
How to Start LeetCode from ZERO in 2025
11:31
Ashish Pratap Singh
Рет қаралды 118 М.
LeetCode Problem: 217. Contains Duplicate | Java Solution
13:04
Code for Interview
Рет қаралды 9 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 680 М.
HashMaps & Dictionaries, Explained Simply
22:44
Nic Barker
Рет қаралды 14 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 689 М.
LeetCode Contains Duplicate Solution Explained - Java
5:28
Nick White
Рет қаралды 103 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 500 М.