349. Intersection of Two Arrays | 4 Approaches | Sorting | 2 Pointer | Hash Set | Binary Search

Поділитися
Вставка
  • Опубліковано 25 сер 2024
  • In this video, I'll talk about how to solve Leetcode 349. Intersection of Two Arrays | Sorting | 2 Pointer | Hash Set | Binary Search
    Checkout DSA-169 Series: • Aryan DSA-169 Series |...
    100Days 100k Placements: • 100 Days 100K Placement
    Let's Connect:
    📝Linkedin: / aryan-mittal-0077
    📸 Instagram: / ez.pz.dsa
    📱Telegram : t.me/aryan_mit...
    🤖 Github: github.com/ary...
    About Me:
    I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
    ✨ Timelines✨
    ✨ Hashtags ✨
    #programming #Interviews #leetcode #faang #maang #datastructures #algorithms

КОМЕНТАРІ • 9

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

    The amount of easy problems lately, gives me a feeling of much Harder problems coming soon 🔜🫠

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

      We are also waiting for 30-50 minutes long videos coming soon 🔜 🌝

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

      Yes same here.

  • @BorisBorovski-mv8fl
    @BorisBorovski-mv8fl 2 місяці тому

    For me the intuitive approach was: Use Map add all elements from the smaller array. The key of the map is the element, the value of the map is the element's occurrence. Then Iterate over the larger one, if it contains the key in the map, first decrement it''s occurrence, if it's 0 remove the key from the map and add the element to the result in both cases. The runtime complexity is O(n + m) and you can solve it fast this way. Btw for cleaner code to take the smaller array you can make a check at the top of the method and return the method with swapped array params. e.g. if (nums1.length > nums2.length) { return intersect(nums2, nums1) }, the intersect is the name of the method.

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

    At 11:30
    Wanna ask
    Meaning, we add a checker at top, which is smaller size (nums1 size or nums2 size), take the smaller one and store into hashset?
    This will improve the space complexity?

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

    Aryan bro when can we get the solution of today's leetcode problem 3 and 4 ?

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

      i think the 3rd one was pretty much easy today
      still i got a WA on it in first try

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

      @@abde3394 can you tell your approach ?