LeetCode 349: Intersection of Two Arrays - Interview Prep Ep 49

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

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

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

    thanks a lot, Sir. Your way of teaching is outstanding.

  • @Chloe-si2hq
    @Chloe-si2hq 2 ปีที่แล้ว +1

    Thank you. All three are very clear and helpful.

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

      Glad it was helpful!

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

    Thank you for all three solutions!

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

    really like your video

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

    I was assuming we should turn the subarray occuring in each of the vectors, so I wrote code that works for all cases but I got a seg-fault even though in my linux system, it passes all of the cases. Probably some cases don't pass in leetcode. Anyways, then I realized the order of the numbers are not considered in this question , just a set is enough to check for the occurences.

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

    This is interesting, it is even more interesting LeetCode accepts your last answer. Here is why, you sort the two arrays at the beginning then compare what occurs at each index to see if they are the same. Does it work for the following array examples?
    {1,2,3,4} and {4,5,6,7} These are pre sorted. So when your code goes to collect the numbers that are the same it wont know that it saw 4 in one set vs the other. Here is an example from wikipedia
    {1,2,3} and {2,3,4} = {2,3}
    But your code says no intersect.

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

      Nah it does work, idk what you're on about. It checks up to the point where both values in the list are the same.

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

    how is the time complexity of the 3rd approach O(nlogn) I thought it would be O(n)

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

      @What's going on I think sorting the arrays takes O(nlog n) time and that dominates the O(n) comparisons later on