Тёмный

Design a Hashset - LeetCode Interview Coding Challenge [Java Brains] 

Java Brains
Подписаться 668 тыс.
Просмотров 77 тыс.
50% 1

In this video we will learn two different solutions to solve the Leetcode problem to design a Hashset for integer values
Interview Question: Design a HashSet without using any built-in hash table libraries.
Leetcode link: leetcode.com/problems/design-...
Difficulty level: Easy
Language: Java
Welcome to the Java Brains Java Interview challenge series of videos where we tackle various coding challenges ranging from the beginner level to advanced level - especially in the context of coding interviews.
Any coding problems you would like me to explore? Please let me know in the comments what you think!
#java #interview #javabrains

Опубликовано:

 

15 сен 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 74   
@nishagandhewar8415
@nishagandhewar8415 3 года назад
Hi, are you planning for Design Patterns.. Looking forward to watch that playlist. Watched multiple videos of design patterns videos, but ur way of explaining is much better than those. Please do plan to crete one playlist for design patterns.
@uma_mataji
@uma_mataji 3 года назад
Thanks Koushik ,you really made it easy to understand the implementation of hashset .
@shahbazalam4565
@shahbazalam4565 3 года назад
Great explanation....Amazing. This channel certainly deserves more subscribers
@prakhar8690
@prakhar8690 2 месяца назад
Awesome! I was asked this in an interview.
@chethan93
@chethan93 3 года назад
Awesome as always!! Koushik please make a playlist on design patterns..!!
@thainarodrigues4605
@thainarodrigues4605 2 года назад
I truly appreciate the explanation!
@douglasharley2440
@douglasharley2440 3 года назад
it seems that the space complexity of the linkedlist implementation approaches O(N) as the number of elements approaches the max element count, and it still suffers from longer lookup times, so the advantage is lost with many elements. i guess the *real* advantage of that linkedlist implementation would be for situations when there aren't many elements...not to mention the fact that simple int key hashcode restricted to a short positive range is never seen irl, so an array of booleans is not realistic. xD as always, GREAT VIDEO! much thanks.
@nikolapetrovic4415
@nikolapetrovic4415 3 года назад
nice one
@shruthis877
@shruthis877 3 года назад
Thanks for the beautiful explanation
@natetolbert3671
@natetolbert3671 3 года назад
Hey Koushik. If you see this, I hope your day is going well. I just wanted to share an idea that I had for your channel. Wanted to run it by you to see what you think. You should add another "Join" tier/perk where members of said tier get to submit a topic of choice into a virtual submissions pool. Once a month (or weekly, bi-weekly, whatever you prefer) you draw a topic from the raffle and make a tutorial on it. Obviously, you would have to place constraints regarding acceptable content. I could see you benefiting greatly from this. If you were to implement a mid tier at ~$5, you would likely get quite a few new members. Especially if you decide to "shout out" the person whose topic is chosen in the resulting video. As an added bonus, you could spin a new series out of the ordeal. Off-the-cuff dev tutorials! I think these would likely end up being my favorite videos. IMPROV!!! I guarantee the audience response would be favorable. All in all, it seems like a win-win to me. It is at least worth trying out. I just came up with the idea, so, as far as I know, it is completely original on YT.
@VarunVishwakarma1
@VarunVishwakarma1 3 года назад
As usual, simple and crisp. Please make videos on system design.
@basheeral-momani2032
@basheeral-momani2032 2 года назад
this is the second I see you, and Im happy to see you, keep the good work
@WanderWithWadhera
@WanderWithWadhera 3 года назад
great dude.. it very simple to understand 👍🏻👏🏻
@rathan235
@rathan235 Год назад
Absolutely helpful
@sambit8011
@sambit8011 3 года назад
Please a video on Design a HashMap (as most of the interviews I'm getting the question "What is the internal of HashMap")...
@NeryNicolas
@NeryNicolas 3 года назад
this explanation qualifies for hashmap too, on how buckets are allocated
@saurabhbatheja
@saurabhbatheja 3 года назад
Just to help, the hashset internally uses a hashmap, with Object as value, it operates with the same principles just with a constant value because that isn't required obviously. BTW your name reminds me of someone, #justkidding :)
@payaltiwari9415
@payaltiwari9415 3 года назад
I m glad i came across your videos. Pls can you make videos for java for beginners too.. you hv all the content of hava just not the basics. Request to pls cover them too.
@bobby4320
@bobby4320 3 года назад
Hi sir, please do some series of tutorials of "collections " , waiting for your new collections playlist
@techocean6372
@techocean6372 3 года назад
delightful video
@nagarajukp7820
@nagarajukp7820 3 года назад
Nice video. Thanks
@thekapila
@thekapila 7 месяцев назад
Hey there! I have really learnt a lot from the interview coding challenges and some of your other outputs. I am trying to obtain a role as a Java developer and have interviews set up. I have been through this entire playlist. Do you have another tips?
@teodoratechie
@teodoratechie Год назад
this man is everything
@guruprasadmahapatro5172
@guruprasadmahapatro5172 3 года назад
Hi sir..I am a big fan of you, please do a tutorial on how the IT industry does continuous integration and continuous deployment of the spring boot application.
@vishnusudarsanam5375
@vishnusudarsanam5375 2 года назад
Should rehashing decrease the number of buckets and readjust the hash table accordingly if we perform too many remove operations?
@hemaladani4510
@hemaladani4510 3 года назад
very simple explanation. Thank you so much!
@hemaladani4510
@hemaladani4510 3 года назад
Why not use ArrayList as child list and use LinkedList?
@dowlathbashag65
@dowlathbashag65 3 года назад
Hello Kaushik, I hope you are doing good. Want to know how you are mapping with ipad with system. when you draw something. its showing simultaneously in the screen. Could you suggest how to do this.
@chaitanyatanwar8151
@chaitanyatanwar8151 3 года назад
Thank you!
@rinkeshgoyal1251
@rinkeshgoyal1251 3 года назад
How we can create a function to get the value at particular index which is send by user?
@shekhar_2014
@shekhar_2014 3 года назад
Really a nice vdo.. Can youplease share a vdo on Memory management in JAVA sir ? It will be really helpful .
@kumar29nov
@kumar29nov 3 года назад
Video Request: java 11 features introduced after java 8. Since it's the latest lts version would be good to know what's happening in Java world
@AjayKumar-fd9mv
@AjayKumar-fd9mv 3 года назад
Great
@therighteous802
@therighteous802 3 года назад
Space complexity on the simple solution is not O(n). Problem states there are at most 10k operations, so at most 10k adds, so n is 10k. But you'd be allocating way more than that.
@IndiansAtBangkok
@IndiansAtBangkok 3 года назад
Tutorial Request on: microservices communication using kafka
@galboss7673
@galboss7673 3 года назад
could you please make a video explaining how to make a Digest authentication with Jersey(JAX-RS) on java?
@aaaa1111222233331
@aaaa1111222233331 3 года назад
Hey nice explanation. How are you avoiding duplicates avoiding here?
@bhanuagrawal8156
@bhanuagrawal8156 3 года назад
Please provide video on hashmap implementation, thanks.
@vivekmuralidharan4913
@vivekmuralidharan4913 3 года назад
I love your videos. Thanks a lot for posting them. I have a query. In the list solution, while adding an element, it is being checked with only a specific bucket obtained of the hashed index. What if the element is already present in another bucket and never being checked? Wont that create duplicate elements to hashset which is contrary to behavior of hashset?
@veipuniilana1842
@veipuniilana1842 2 года назад
that is not possible i guess, becuase hash function is same for all the key, so whenever you enter the key it will go to that particular backet you just entered before.
@SoloGamer-23
@SoloGamer-23 3 года назад
Sir please upload videos on Node and express js ,Your content is amazing and I didn't find any other thoughtful tutorial on node js other then yours ,So please sir make video on Node and express
@Java.Brains
@Java.Brains 3 года назад
You should subscribe to my channel :) I already have many Node.js videos for you to watch and enjoy! As for Express, I'll work on it!
@vyshnavramesh9305
@vyshnavramesh9305 3 года назад
Have been watching JB for 3 years now specificaly for Java. Started watching J2EE, Hibernate and Spring Boot playlists to get my first job, used the same for 2nd job. Then continued to microservices playlist for 3rd job now. For my 4th job, could you create playlists for Leetcode Top interview Qs and CTCI Chapter wise Qs? There are bits and pieces of these already online, but not even one is reliable to be the single point of contact. As an aspiring FAANG candidate, I hope I 'm raising the voices of many
@rafimangrio4537
@rafimangrio4537 3 года назад
Please start a DSA series
@shubhampatel7870
@shubhampatel7870 3 года назад
21:50 what if the key is not present but the childList is not null. It contains some other element. I think we should handle that case as well? e.g. 1001%100 = 1 but the bucket 1 contains 1901 which can be in the same bucket due to collisions. Am I missing something?
@jimmymehta5237
@jimmymehta5237 3 года назад
that is good to have but lets say 1901 in bucket 1 and 1001 remove comes , so we'll remove 1001 (which dont exist) ,so no effect.I mean it will not have any problem.
@theswarajdeshmukh
@theswarajdeshmukh 3 года назад
like before watching it ...
@adityaverma1172
@adityaverma1172 3 года назад
I was asked this question in an interview, I too used ArrayList but he clearly said that we cannot use any existing library to implement it. So can we implement this using simple array or some custom DS.
@tarunkumargola7633
@tarunkumargola7633 3 года назад
Can you tell me how you implemented it without any existing library?
@vishalgupta9156
@vishalgupta9156 3 года назад
Didn't you take care to not add duplicates in hashset ?
@naughtynawaz
@naughtynawaz 3 года назад
Make a video on map and thread plzz
@ashishkumarsingh6618
@ashishkumarsingh6618 Год назад
Why you didn't use MAX_VALUE mentioned as instance variable
@JohnDoe-ej6vm
@JohnDoe-ej6vm Год назад
You did not use this MAX_VALUE any where in the code then what was the purpose of its declaration ? private final int MAX_VALUE = 1000000;
@jimmymehta5237
@jimmymehta5237 3 года назад
I am using above code and in leetcode it is failing for one of the test case. After debugging, find out that, when I add 48 first time, it is creating index 48 and add on that. when i check contains(48) then it returns NULL, and i debug it and saw it that it stores at index 49, Is it because we used ArrayList and it is 0 based index?
@harshbiyani3048
@harshbiyani3048 3 года назад
Use set() instead of add when adding the childList to parentList.
@parasghai28
@parasghai28 3 года назад
@@harshbiyani3048 my test case was also failing but replacing add with set worked. But I didt understand why
@yoshifan102
@yoshifan102 8 месяцев назад
I had the same problem
@sivakrishnat5471
@sivakrishnat5471 2 года назад
what is the point of this interview question? isn't it reinventing the wheel?
@ratneshchouhan6
@ratneshchouhan6 3 года назад
@javabrains Hi Koushik, another nicely explained video, However, I have another solution by just taking a cue out your array solution, in the array solution, The solution wasn't efficient because of space complexity but we can reduce it by using bit array of the highest limit this way we'll require only those many bits space and time complexity will also be of O(1). What do you think?
@ratneshchouhan6
@ratneshchouhan6 3 года назад
@Jorge Morando Yes , exactly👍 and the prob was not time complexity but the space one.
@amrholo4445
@amrholo4445 2 года назад
Thanks a lot, sir
@nharshal
@nharshal 3 года назад
Need video series on design patterns
@douglasharley2440
@douglasharley2440 3 года назад
imo, design patterns just aren't that applicable for developers any more. generally, the system architecture is defined by whatever well-established framework you are using, so a system implementation is primarily just business logic leveraging the framework(s). obviously, the story is very different if you are building a framework, or server or something like that, from-scratch, and you'll need to make use of plenty of patterns, but that's just not something the average developer needs to concern themselves with in their actual job. it's much more important to stay abreast of the explosion of frameworks, and platforms, and services, and apis, and languages, and protocols, and...lol, just the topic of javascript front-end build tools (NPM, Gulp, Grunt, Webpack, etc.) is already daunting, and getting more so all the time! GoF just isn't really relevant to software anymore i'd argue. peace
@techocean6372
@techocean6372 3 года назад
@@douglasharley2440 you are right , design patterns ,configuring logs,config files all are made easy in frameworks .
@alxx736
@alxx736 3 года назад
Why LinkedList and not List?
@danthe1st
@danthe1st 3 года назад
Just wrap HashMap, that is how HashSet works. It is not using HashSet ;) It is not even using a Set
@anandgupta8529
@anandgupta8529 3 года назад
shut up
@balakrishnanu2061
@balakrishnanu2061 3 года назад
What Dan said is true. As I remember, Hashset in Java is Hashmap of type or so. There would be a key which is Hashset value, but no value in the map.
@danthe1st
@danthe1st 3 года назад
The key and the value is the same if I remember correctly but I am not sure.
@danthe1st
@danthe1st 3 года назад
If you look at the sources of HashSet(OpenJDK: github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/util/HashSet.java), you can clearly see that it uses a HashMap where a reference to a new Object (constant) is used for all values present.
@balakrishnanu2061
@balakrishnanu2061 3 года назад
@@danthe1st Ah, yes. So it's a blank object. I remember something constant was used. It's not null. 😅 Guess its time to start again, it's been more than 2 years since I wrote a program in Java.
@kumar29nov
@kumar29nov 3 года назад
LPT: Simple implementation is like a programming joke. do not seriously give that to interviewer as final solution, you can joke about it, but not as final solution. ;) Because the main problem "Hash" concepts solve is lack of sequential memory. It aims to strike a balance between lack of sequential memory in array implementation and having to traverse through all values in linked list
Далее
🔔 Top 5 mistakes with Java Sets!
17:58
Просмотров 25 тыс.
СПАЛИЛА МАМЕ СТАРШУЮ СЕСТРУ
00:23
Победитель евровидения
00:18
Просмотров 20 тыс.
НОВАЯ ПАСХАЛКА В ЯНДЕКСЕ
00:20
Просмотров 505 тыс.
Design Hashmap - Leetcode 706 - Python
14:30
Просмотров 28 тыс.
Set and HashSet in Java - Full Tutorial
20:43
Просмотров 204 тыс.
4 Spring Boot Mistakes to AVOID in 2024
15:18
Просмотров 55 тыс.
СПАЛИЛА МАМЕ СТАРШУЮ СЕСТРУ
00:23