LeetCode 350 | Intersection of Two Arrays II | Solution Explained (Java + Whiteboard)

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 ต.ค. 2024

ความคิดเห็น • 43

  • @fsxaviator
    @fsxaviator 3 ปีที่แล้ว +6

    Thank you!!! Finally, this was the first explanation I was actually able to understand.

  • @JordanTaylor-y4f
    @JordanTaylor-y4f ปีที่แล้ว

    Thank you. I have always wondered why there was a pre-increment and a post increment, and this is a perfect use case for post-increment. It's the small things sometimes. I've never seen that before.

  • @Priyam6F4
    @Priyam6F4 ปีที่แล้ว +2

    Hey. The solution doesn't work for : int[] arr1 = {4,9,5};
    int[] arr2 = {9,4,9,8,4}; please check.

  • @athangkulkarni8245
    @athangkulkarni8245 11 หลายเดือนก่อน

    At max, minimum of size of both arrays can be duplicates, so instead of doing length1 * length2, you can do min(length1, length2)

  • @someshsahu4638
    @someshsahu4638 ปีที่แล้ว +1

    Very nice explanation thankyou 🙏🏼🙏🏼🙏🏼

  • @sayantaniguha8519
    @sayantaniguha8519 2 ปีที่แล้ว

    Finally an explanation using constant space!

  • @ritchievales
    @ritchievales 2 ปีที่แล้ว

    I had it so close.... I was increasing the indexes depending on nums1 and nums2 sizes... that approach worked for a few testcases but I couldn't figure out until saw this video, thanks! For sure I was not able to solve it by myself but still learned a lot :)

  • @HenggaoCai
    @HenggaoCai 4 ปีที่แล้ว +1

    Keep up the good work! You're doing great.

  • @sasgaro
    @sasgaro 4 ปีที่แล้ว +3

    Great video, you definitely deserve more subs, one note: that music started waaaayyy too early and was kinda unexpected covering your voice over.

    • @xavierelon
      @xavierelon  4 ปีที่แล้ว +2

      Thanks man. And thanks for the critique I'll be sure to fix it. What do you think about my intro I made? I'm still working on it

    • @sasgaro
      @sasgaro 4 ปีที่แล้ว

      @@xavierelon I don't usually pay much attention to intros and for me, the best intro is the one I barely notice and I didn't notice yours. Don't get me wrong, I don't mean it in a bad way, on the contrary
      , I think it's visually great, not irritating like in some channels, and most importantly - short, but people usually come for the content and not for the intros.

    • @xavierelon
      @xavierelon  4 ปีที่แล้ว +2

      Serdar Asgarov awesome thank you for the constructive criticism. Make sure you subscribe if you haven’t already hehe

    • @CD-xd6fm
      @CD-xd6fm 3 ปีที่แล้ว

      @@xavierelon Hey , can you show us how you made your intro bcoz its cool or is it a purchased plugin?

  • @ginasomara267
    @ginasomara267 2 ปีที่แล้ว +1

    nice and understandable!! TY

  • @lighto263
    @lighto263 3 ปีที่แล้ว +1

    Solution without using extra space is amazing thanks! Bit time complexity basically is O(N), isn't it?

    • @xavierelon
      @xavierelon  3 ปีที่แล้ว +1

      Yes should be. Did I forget to mention time complexity in this video? Sorry if so

    • @vikasraaja5760
      @vikasraaja5760 2 ปีที่แล้ว

      Wouldn't it be O(nlogn) because that's the time complexity of Arrays.sort()?

    • @yogeshyts
      @yogeshyts 2 ปีที่แล้ว +1

      @@vikasraaja5760 lgta h timeComplexity india m jada matter krti h

    • @peterpace3379
      @peterpace3379 ปีที่แล้ว +1

      ​@@yogeshyts of course, har company ke coding round mein aata hai ye sab

  • @pubamx
    @pubamx 3 ปีที่แล้ว +1

    Great explanation. Just wasn't clear to me why SC is O(logm + long). Is it due to the sort of arrays generates overrides the initial value of nums array or why? Thanks in advance.

  • @nishukumari8791
    @nishukumari8791 6 หลายเดือนก่อน

    waw its really simple and awesome

  • @monikajha3500
    @monikajha3500 3 ปีที่แล้ว +1

    I am little confused about the third array(ans) size as length1 * length2. Can we take the size as the smallest of length1 and length2?

    • @monikajha3500
      @monikajha3500 3 ปีที่แล้ว

      Oops ! sorry. I commented before I finished this video...

    • @Candyroxnrulz
      @Candyroxnrulz 2 ปีที่แล้ว

      wait i still don't get it why

  • @adithyang6672
    @adithyang6672 ปีที่แล้ว

    What about the values which are already present in nums1 how are they getting deleted

  • @AbhishekKumar-ff9vg
    @AbhishekKumar-ff9vg 3 ปีที่แล้ว +1

    how to implement the same in c++ with same space com.
    i tried but more elements are getting copied can you give code for same. thanks for video

  • @bina.soche.samjhe
    @bina.soche.samjhe ปีที่แล้ว

    why did we use nums1 and not nums2 to store the common elements

  • @odongoemmanuel885
    @odongoemmanuel885 2 ปีที่แล้ว

    where are you getting the nums in return Arrays.copyOfRange(nums, 0, k);

  • @sayantaniguha8519
    @sayantaniguha8519 2 ปีที่แล้ว

    How is the space *O(log m + log n)* ?

  • @qianjun1856
    @qianjun1856 2 ปีที่แล้ว

    Am I missing anything, I feel this algorithm is not working.
    A=[1,2,2,1,3,2]
    B=[1,2,3]
    A_sorted=[1,1,2,2,2,3]
    expected output: [1,2]
    The Algorithm will produce[1,2,3]

    • @Kreedlord
      @Kreedlord 2 ปีที่แล้ว

      expected output is actually 1,2,3...d problem is to find intersection, similar-distinct elements in both array

  • @pqr.priyanshu
    @pqr.priyanshu 2 ปีที่แล้ว

    Which software do you use as a whiteboard??
    thanks

    • @xavierelon
      @xavierelon  2 ปีที่แล้ว +1

      Goodnotes on my ipad

    • @pqr.priyanshu
      @pqr.priyanshu 2 ปีที่แล้ว

      @@xavierelon thanks ❤️

  • @samareshms4591
    @samareshms4591 2 ปีที่แล้ว

    could have optimized to O(mlogm + n)

  • @artemvolkov5682
    @artemvolkov5682 10 หลายเดือนก่อน

    So smart to add background music while you're unable to articulate well the n/m complexity. I've broken my ears