HashMaps in Python Tutorial - Data Structures for Coding Interviews

Поділитися
Вставка
  • Опубліковано 13 чер 2024
  • Data structures are one of the most important things to prepare for coding interviews. HashMaps are one of the most essential data structures to know, and today we'll be learning how they work, what their benefits are, and solving a practice problem together using Python.
    📘 Chapters
    0:00 - Intro
    0:43 - Explaining HashMaps
    6:47 - Example Coding Problem
    🔗 Resources
    LeetCode Problem: leetcode.com/problems/group-a...
    🎵 Music
    Brontosaurus - Dylan Sitts
    Deadlines - Dylan Sitts
    Pick Up Your Phone Please - baegel
    Slapperoni Pizza - Jobii
    #coding #softwareengineer #python
  • Наука та технологія

КОМЕНТАРІ • 111

  • @Codebagel
    @Codebagel  5 місяців тому +17

    After a year hiatus (sorry, got busy with work!) this series is continuing! Check the next video out here: ua-cam.com/video/7gWFRA0V0OE/v-deo.html

    • @danyahsan3958
      @danyahsan3958 2 місяці тому

      Please moreee nd in java

    • @alanyates6377
      @alanyates6377 Місяць тому

      Thanks bro, eagerly waiting for your content.

  • @NeetCode
    @NeetCode Рік тому +199

    Great stuff! Super underrated channel (but not for long i bet =) )

    • @Codebagel
      @Codebagel  Рік тому +45

      NO WAY YOU COMMENTED! Thank you so much, you’re actually the reason I was inspired to start this channel so I really appreciate you commenting!
      PS: everyone go sub to this man, single-handedly helped me get a job :)

    • @eternalpanic1
      @eternalpanic1 Рік тому +5

      Yooo NeetCode is here yay!!!!

    • @hamoodhabibi7026
      @hamoodhabibi7026 Рік тому +5

      !!! Ur both great 👍

    • @kvelez
      @kvelez 7 місяців тому +1

      Good chanel

    • @mohammadkaif2534
      @mohammadkaif2534 6 місяців тому

      bhai saxx tha aur bnao

  • @samm4258
    @samm4258 Рік тому +14

    After 4 days of struggling, this video finally gave me the breakthrough to understand hash maps in my self taught journey. Concise and coherent, this is the best tutorial video I've seen so far!

  • @sugaslate14
    @sugaslate14 8 місяців тому +2

    I love the fact you go through an actual problem at the end. That made it “click” for me. New sub here, please keep it coming!

  • @sidandhawa
    @sidandhawa Рік тому +4

    The explanation on this was so clear. Absolutely brilliant. You have gained a new subscriber and I can't wait to see this channel grow the way it deserves to!

  • @realbutters
    @realbutters Рік тому +5

    Great video. It’s hard to strike the balance between keeping things concise while also exploring them fully, but you did an incredible job of it here.

  • @bogdan8204
    @bogdan8204 5 місяців тому +5

    this is first video, but i'm already excitement about learn next algoritm in this series. The best.

    • @Codebagel
      @Codebagel  5 місяців тому +2

      Just uploaded the newest one after a long break!

  • @kaiser5026
    @kaiser5026 Рік тому +10

    Not even half way through this video and I just want to give props to how concise the information is. I hope to see some machine learning content soon :)

  • @futhedude4848
    @futhedude4848 10 місяців тому +2

    great hash map explaination, plus it have leetcode example and explaination for the answer in detail at the end of the video which is really great.

  • @panwilku6146
    @panwilku6146 3 місяці тому

    I watched this video like 3 times over a month ago, and I was struggling with understanding the logic even though you tried so hard to explain it. Now, after some practice, I watched this video once again and I can say I understand the code perfectly now. I just wrote the code before seeing the solution. Thank you for yours videos, one of the best channels out there!

  • @Salmo_103
    @Salmo_103 6 місяців тому

    The best explanation I found about this topic yet! Thank you so much, God bless you

  • @blackshadowproductions5144
    @blackshadowproductions5144 3 місяці тому

    Your explanation is simply the best one I found, thank you so much man!

  • @misslaurenbecca
    @misslaurenbecca 2 місяці тому +1

    Great video. After I watched your video, I tried to code it myself without looking and tried to do it without defaultdict(), just adding my first val as a list and then appending to the list for the following ones. After I had done that, I converted it to be like yours. Besides the obvious benefits, something else I realized was doing it your way removed the need to check if a key was already in the dictionary. In my version, I had to make that check, otherwise, I would be attempting to append to a list that hadn't been created yet.

  • @vantuantran225
    @vantuantran225 Рік тому

    That's incredible, I understand it right now. Thanks you, it really simple explaination and easy to understand

  • @jaganmayeesahoo4210
    @jaganmayeesahoo4210 6 місяців тому

    wow, still wrapping my head, I am new to it, but its very concise and all good content, man.

  • @dhirajsahu2026
    @dhirajsahu2026 11 місяців тому

    Great Work! Nice Explanation Dude. Really helpful

  • @alejandroolaria
    @alejandroolaria Рік тому

    This is awesome! thank you very much for making this video!

  • @mrzhambyl
    @mrzhambyl Рік тому

    IMO, best explanation on YT

  • @spiritual5750
    @spiritual5750 Рік тому +1

    Seriously man, i could see your hard work through this video.

    • @Codebagel
      @Codebagel  Рік тому

      Thank you so much! That means a lot :)

  • @aninditabatra3810
    @aninditabatra3810 9 місяців тому +1

    great content and will continue to watch in the future :)

  • @drstrangeluv1680
    @drstrangeluv1680 Місяць тому

    The video was great! However, if you use the SORT method, the best time complexity you would get is O(nlogn).
    If you want to solve it in O(n), a clever approach is to first check every word and create a key value pair of every letter.
    For example, you go through the first word and get 3 'a', 2 't' and 4 'e'. Now you save this in a dict { 'a':3,' t':2, 'e':4 }. Then, you go through every other word and do the same. If you find any other word with 3 'a', 2 't' and 4 'e', you have found an anagram.
    So just comparing the dicts at the end would give you the anagrams. You would go through the list only once so you have time complexity O(n).
    P.S. you should first check if two words are the same length. If not, you can automatically cancel them as anagrams.

  • @saatvik1
    @saatvik1 4 місяці тому

    Lovely Vid!! Great Work

  • @jamalghatit
    @jamalghatit 9 місяців тому

    Great job! thanks for your video

  • @BAMBAMBAMBAMBAMval
    @BAMBAMBAMBAMBAMval Рік тому +4

    This is what should be ranked #1 when searching for "python hashmap"

    • @Codebagel
      @Codebagel  Рік тому +1

      Thank you!! I’ll be making the full series soon so don’t worry!

  • @auzee4925
    @auzee4925 4 місяці тому +1

    city_map = {}
    cities = ["Calgary", "Vancouver","Toronto"]
    city_map["Canada"]= cities
    # This works so much better

    • @hopeeternal7470
      @hopeeternal7470 4 місяці тому

      Yeah I'm not sure why he did the extra step. Like he took two minutes to look up w3school article on dictionaries and made a video out of it.

  • @md.mahbubanamtanim9081
    @md.mahbubanamtanim9081 Місяць тому

    Excellent!!

  • @CarlosLopez-fg3fl
    @CarlosLopez-fg3fl 3 місяці тому

    You're great, good explanations

  • @servantofthelord8147
    @servantofthelord8147 9 місяців тому

    Wow. It makes sense now. It finally makes sense. Thank you!

    • @Codebagel
      @Codebagel  9 місяців тому

      You're welcome! I'll finish up the series in the coming weeks!

  • @willmccauley22
    @willmccauley22 7 місяців тому

    Appreciate the video, well explained 👍

  • @denatolix
    @denatolix 11 місяців тому

    Thanks! You really help me! Wish you 1m subs and more

  • @AdityaRaj-xm6oi
    @AdityaRaj-xm6oi 9 місяців тому +2

    This was a really amazing learning video, I like your style of teaching that first of all you made the concept clear and then a question to make it more clear.
    Btw I was here because I didn't get clarity with the neetcode channel of the same question. so I request you to upload these types of videos more thanks 🙏

    • @Codebagel
      @Codebagel  9 місяців тому

      Glad you enjoyed it! I'll see what I can do!

  • @InDaHoops
    @InDaHoops 4 місяці тому

    So, ive been programming in python for a little over a year, and i've always seen those hashmap memes, and how they're the solution to everything, but the name Hashmap just seems intimidating, so i never bothered thinking about using one or looking up what it is...until this day, when i realized its just a dictionary, and I've been using them all the time lol Great video, keep it up!

  • @abhisheksharma10600
    @abhisheksharma10600 3 місяці тому +1

    Please complete this playlist, its really helpful. Btw i just subscribed so keep up the work please.

  • @bhavybhatt4571
    @bhavybhatt4571 4 місяці тому +1

    hey bro thank you so much don't focus on views just post and you'll make historical content as your vids are easy to understand because of the analogies you use thank you so much buddy lots of love from india

  • @vazp3
    @vazp3 Місяць тому +1

    great video :)

  • @shortandshine8279
    @shortandshine8279 9 місяців тому

    Awesome, keep it up

  • @chamarr
    @chamarr Рік тому +1

    Goat vid codebagel, do more implementation vids!!!

    • @Codebagel
      @Codebagel  Рік тому

      Thanks so much! I’ll keep on making them!

  • @brianc.3609
    @brianc.3609 10 місяців тому

    love this video!!!!!

  • @zohayer.mehtab
    @zohayer.mehtab 5 місяців тому

    Thank you so much!

  • @samstar1290
    @samstar1290 9 місяців тому +1

    Please make videos often , stuff is great and smooth

    • @Codebagel
      @Codebagel  9 місяців тому

      Have one coming out tomorrow!

  • @KanjiBBB
    @KanjiBBB 11 місяців тому

    ngl ur actaully a good teacher

  • @nalininadupalli3131
    @nalininadupalli3131 Рік тому

    Hello, thanks for a great video! Can you also please explain if Hash Tables and Hash Maps are the same (in general) ? If different, how does python dictionary Data structure handle them?
    thanks so much in advance !

  • @livelikeawarrior9180
    @livelikeawarrior9180 10 місяців тому

    Damn, that's a very good video ...

  • @manickamm2671
    @manickamm2671 8 місяців тому

    Great channel

  • @dsa0decoded
    @dsa0decoded 11 місяців тому

    Great Explanation you should make more videos

    • @Codebagel
      @Codebagel  9 місяців тому

      Thank you! I plan on doing it a lot more frequently over the coming months!

  • @MysteryIlusion
    @MysteryIlusion 9 місяців тому

    Can I just return anagram_map.values() instead of the result list? I'm not sure if there's some kind of issue later on but is it faster to do it by returning values since it is already in list form rather than adding 1 more for loop?

  • @mansikumari4954
    @mansikumari4954 8 місяців тому

    Simply Wow - from a noob!!

  • @ashraf_isb
    @ashraf_isb 3 місяці тому

    thank you

  • @krishnapathak9362
    @krishnapathak9362 3 місяці тому

    Hey codebagel i request you to please upload complete dsa playlist using c++ and loved your amazing content

  • @ManojMallisetti
    @ManojMallisetti Місяць тому

    where did you created the module collection

  • @yoman6367
    @yoman6367 Місяць тому

    can we use long long type and do bit-masking?

  • @vellankiindeevar5530
    @vellankiindeevar5530 Рік тому

    bro do more vids about all dsa pls , this vid is really good

  • @sak.4001
    @sak.4001 5 місяців тому

    underrated

  • @bogdan8204
    @bogdan8204 5 місяців тому

    the best ....

  • @pauolive7239
    @pauolive7239 Рік тому +1

    But isn't sorting each of the strings inside the loop making the time complexity O(n * nlogn)?

  • @speedoi-bh7kg
    @speedoi-bh7kg 9 місяців тому +1

    nice job keep going =)

  • @Locus616
    @Locus616 Місяць тому

    wao wao wao

  • @ooogabooga5111
    @ooogabooga5111 4 місяці тому

    sorting has its time complexity right, how is this optimal? who decides that?

  • @L00p69
    @L00p69 Місяць тому

    thanks WholeHeartedLy !!

  • @notmimul
    @notmimul 3 місяці тому

    for the results, you could just use
    result = list(anagram_map.values())
    correct me if this is not the correct way. tq

  • @francois-xaviermenage4531
    @francois-xaviermenage4531 3 місяці тому

    Are hash maps and hash tables really the same?

  • @futhedude4848
    @futhedude4848 10 місяців тому

    Man, this channel only have 19 videos at this time.
    I wish you could do more about algorithms and data structure.

    • @Codebagel
      @Codebagel  9 місяців тому +1

      Been getting lots of positive feedback on it, so I'll get back to working on the series in the coming weeks!

    • @futhedude4848
      @futhedude4848 9 місяців тому

      @@Codebagel thanks. i'm waiting for it.

    • @Codebagel
      @Codebagel  5 місяців тому +1

      @@futhedude4848just uploaded, took a lot longer than I expected but it’s out now!

    • @futhedude4848
      @futhedude4848 5 місяців тому

      @@Codebagel thanks, i'll check it

  • @TimurKupaev
    @TimurKupaev Місяць тому

    I don’t think you can use import for
    the most of the interviews

  • @freecontent2438
    @freecontent2438 Рік тому

    Dammm🎉

  • @Bond00.7
    @Bond00.7 Рік тому +1

    Bro why didnt you continued this series 😢 plz tell us if u moved to another channel we need you

  • @markopancic6060
    @markopancic6060 Рік тому

    For the result you should have just called .values no?

  • @ooogabooga5111
    @ooogabooga5111 4 місяці тому

    how simple, i didn't it was this simple to think. Find two numbers which gives the sum 10 from a list of number lets says [ 1, -3, 4, 6 , 9 ]. So here I would say for 1 the number is 9, -3 its 13 so on. So essentially I created a dictionary (hash map) with key as the result of 10-1, so when I want to check for the next number is the one, i can just check arr[9] and if its present then I have the first solution. Damn..
    To make it even more simple, you take your question process it for every element in the array in a way that the dictionary benifits from the result you generate. Ig thats hashmap, its just making dictionary. In that logic an array is a hashmap where the key is already defined. so its O(1) from start, but for hashmaps sinse you need to check every element to create a hashmap the the program is O(n) or more as it depends on question but once the hashmap is created the order its exec is O(1)

  • @coolsidshant297
    @coolsidshant297 Рік тому +1

    Your content is way better than any paid one ,but you seriously need to do marketing ,make some content related to india and your channel will get some instant boost , make a video on "Top 10 common python algorithms asked by Maang in India" ,btw love from India

    • @Codebagel
      @Codebagel  Рік тому

      Thank you so much! I have a bit of a long-term plan in mind regarding this, I’ll definitely add that video to the list though! :)

  • @prao2tapper
    @prao2tapper 7 місяців тому +1

    why did such a small code at the end take such a long time for me to understand

  • @pixiepastels1070
    @pixiepastels1070 4 місяці тому

    why do another for loop why not just return anagram_map.values() ? it already returns a list and the values are in a list so its already a list of lists

    • @xa6859
      @xa6859 4 місяці тому

      Because of the `defaultdict(list)` => "TypeError: 'list' object is not callable". You will need `list(anagram_map.values())`

  • @rayaqin
    @rayaqin 3 місяці тому

    using the equal sign to denote a key -> value connection is not a good choice imo

  • @user-vn2bg9ch8r
    @user-vn2bg9ch8r 8 місяців тому

    dude like wtf, dthe moment you said city_map = dict() i was like wtf, i've be working with hashmaps for the past 6 months and i had no clue

  • @kadspy
    @kadspy 7 місяців тому

    Dude, you have used sorted inside a loop, isn't it increases a time complexity.. Here, you are claiming O(n) but i think its greater than that because sorting function of python also taking some time complexity based on "n".

  • @lahoussinezeggwagh608
    @lahoussinezeggwagh608 Рік тому +1

    Please dsa in cpp

    • @Codebagel
      @Codebagel  Рік тому

      Will do in the near future!

  • @SashoSuper
    @SashoSuper 3 місяці тому

    And I had to search in Japanese to find the video, even better.

  • @Locus616
    @Locus616 Місяць тому

    you make good coffee wao wao wao wao

  • @sheryarbaloch67
    @sheryarbaloch67 3 місяці тому

    Kinda felt happy to see Pakistan in the example, i don't know why😂

  • @angelicking2890
    @angelicking2890 Рік тому +1

    Why the funny names in programming? This always happens whenever I try to resolve a problem. Why can't they just say it how it is ? I was intimidating hearing a crazy word like HashMaps only to find out I've been using them the whole time, dictionaries. Same goes for relational databases. I've been using them the whole time but because I didn't know what the interviewer meant by relational, I messed it up and she gave me an eyeball like I was a fraud. I still remember the "oooOOk Kaaaay". Just say , "you know the database with manytomanyfield or onetoonefield?" instead of these nonsensical words. Talk practical not theory. Idiots.. Sorry for the rant, it's just these funny names can trip up people.

  • @gy7230
    @gy7230 10 місяців тому

    Amazing Man, you and @Neetcode are the best channels for learning python

    • @Codebagel
      @Codebagel  9 місяців тому +1

      Thank you for the kind words! I'll finish up the series in the coming weeks!

  • @kvelez
    @kvelez 7 місяців тому +1

    **Keep uploading more LeetCode, NeetCode, DataStructures and Algos.
    cities = ["Calgary", "Vancouver", "Toronto"]
    city_map = {"Canada":[]}
    city_map.update({"Canada":cities})
    print(city_map)
    ============================
    from collections import defaultdict
    class Anagram:
    def group_anagrams(self, strs):
    anagram_map = defaultdict(list)
    for s in strs:
    anagram_map[tuple(sorted(s))].append(s)
    return list(anagram_map.values())
    anagrams = Anagram()
    print(anagrams.group_anagrams(["eat", "tea", "tan", "ate", "nat", "bat"]))

    • @xa6859
      @xa6859 4 місяці тому

      I like the `return list(anagram_map.values())` instead of doing a second loop.

  • @labs2612
    @labs2612 4 місяці тому

    You're amazing thank you so much 😭🩷