Intersection of Two Arrays II | Leetcode 350 | Live coding session

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

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

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

    What an amazing approach. In fact, I did something similar. That means I've started to leverage my algorithms problems solve skills and your channel has helped me a lot. Thank you for all your efforts.

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

    I did today's question without watching your video
    but still here's a like from me XD

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

    It can also be done by using one array of size 1001 instead of two :)

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

    If possible can we also discuss the follow up questions mentioned at the bottom in the question. I think it will be really helpful for coding interviews.

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

      My idea of follow ups questions are as follows:
      1. If the input array is sorted, use a two pointer technique(similar to what we do in merge sort). Place two pointers i = 0 and j = 0, if nums[i] is smaller than nums[j], increment i, if greater increment j, else place the element in a vector as they are equal.
      2. If num1 size is smaller, build the hashmap on the smaller size as it will consume less memory.Then apply the approach as told in the video.
      3. If nums2 can't be loaded in disk, check if nums1 can be loaded. If yes, build the hashmap in terms of nums1(Similar to point 2). If none can be loaded and since we are given that range can be 0 - 1000, maybe we can try to split the array in ranges. Like, 0 - 250, 250-500, 500-750 and 750-1000. Like this we can load every element from both arrays. Now, I can't think on how we can split range in case, the range is high, like 10^9.
      Edit - I think we can use external sorting here - www.geeksforgeeks.org/external-sorting/
      Please correct me, if I told something incorrect in any of these

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

      @@koulicksadhu7679 Adding on to that, also if the array is sorted then we can first apply binary search for element (which will be minimum of a[0] and b[0]) to get the potential starting in points in both array.
      This way we can avoid cases like -
      A[] = {1, 1 . . .} and B[] = {2, 2 . . .}.
      In cases like we can avoid unwanted comparisons.
      Hope that makes sense!!

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

    I solve this problem using hashmaps that gets accepted
    Is it a correct approach