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.
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.
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
@@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!!
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.
Music to my ears dude
I did today's question without watching your video
but still here's a like from me XD
Thanks Shantanu 😍
It can also be done by using one array of size 1001 instead of two :)
Absolutely, but I feel cleaner the better.
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.
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
@@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!!
I solve this problem using hashmaps that gets accepted
Is it a correct approach
Yes, absolutely