i coded the first part by myself fully,,,,,but the second part i could not get the logic of storing in variables at first........but then i get the logic
How is this binary search ? I could have solved it, its very simple linear process. But because its inside binary search i stuck finding Binary Search approach.
there is another binary search way idk which he didn't show...but i tried to do it with another approach which gives TC of O(logn)xO(logm) instead of which striver showed was TC O(log(m+n)) so for smaller input this striver method will be good but for large inputs that binary search approach wil be better
i did not understand the count method for looking index 1 and index 2, untill then it was fine but then what are looking for like how index 1 will be that element only ??
you can actually break once you found both ind1 and ind2 elements. im not sure why he didnt do it. index1 will be that element only because count will only get incremented after you find it. you will ONLY reach index1 count once and only once.
If someone is looking for a less redundant code: class Solution: def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float: n1,n2 = len(nums1),len(nums2) n = n1+n2 ind1,ind2 = n//2-1,n//2 count = 0 i,j = 0,0 while i
Public class solution { Public static double median (int []a,int []b){ int m=a.length, n=b.length; int i=0,j=0 m1=0,m2=0; for(int count =0;count b[j]){ m1=b[j++]; }else { m1=a[i++]; } } elseif(i
@striver Why not put the OR condition in while loop instead of running while loop separately while merging the array? like while(i< arr1.length || j < arr2.length){
Please watch our new video on the same topic: ua-cam.com/video/F9c7LpRZWVQ/v-deo.html
This better approach is pretty smart I must say. Array is visualized just using two variables, amazing.
15:47 - for better SEO.
This is why I like striver RAJ, Straightforward, upto point and honest.
Really good to be like that, helps in longer run.
It's the hard problem on leetcode and you solved it brilliantly , hats off !!
link please
@@VinayakAsati-k9d search krle bhai
you expain it in a such easy manner, so good Striver...
Understood! Super wonderful explanation as always, thank you very very much for your effort!!
बहुत सही गुरु जी जलवा है आपका 😂
Thank You Much for this wonderful video...................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
UnderStood, Wanted to learn this from a long long time.
If You do this bruteforce in Pyhton language then your all test cases will pass
python is really good language
What a brilliant approach!!!
i coded the first part by myself fully,,,,,but the second part i could not get the logic of storing in variables at first........but then i get the logic
Thanks for the detailed explanation
understood, thanks for the perfect explanation
Thanks buddy explaining the concept
class Solution {
public:
double findMedianSortedArrays(vector& nums1, vector& nums2) {
int n2 = nums2.size();
int n1 = nums1.size();
if(n2 2
int mid2 = left - mid1;
int l1 = INT_MIN;
int l2 = INT_MIN;
int r1 = INT_MAX;
int r2 = INT_MAX;
if(mid1 = 0) l2 = nums2[mid2 - 1];
if(r1>=l2 && r2>=l1){
if((n1+n2)%2 != 0){ //odd
return max(l1, l2);
}
else{
return double(max(l1, l2) + min(r1, r2))/2.0;
}
}
else if(l1 > r2){
high = mid1-1;
}
else{
low = mid1+1;
}
}
return -1;
}
}; This is throwing tle, can someone explain the reason and correct the code
How is this binary search ?
I could have solved it, its very simple linear process. But because its inside binary search i stuck finding Binary Search approach.
same :/
My bad the optimal approach is using BS, it's a separate video :(
there is another binary search way idk which he didn't show...but i tried to do it with another approach which gives TC of O(logn)xO(logm) instead of which striver showed was TC O(log(m+n)) so for smaller input this striver method will be good but for large inputs that binary search approach wil be better
i did not understand the count method for looking index 1 and index 2, untill then it was fine but then what are looking for like how index 1 will be that element only ??
you can actually break once you found both ind1 and ind2 elements. im not sure why he didnt do it.
index1 will be that element only because count will only get incremented after you find it. you will ONLY reach index1 count once and only once.
@@vaishnavejp9247 break krne pe 5.5 aa rha h, which is wrong
Thanks bro ...........But still having O(N+M) time complexity. Need further improvements.
Understood✅🔥🔥
UNDERSTOOD
"here comes the twist"
Understood, thank you.
Thank you Bhaiya
its still giving partially accepted
Understood!
where was binary search in this problem striver?
Me thinking of that too.
Ain't this normal array question???
watch the optimal solution dude
Understood
Understood !! 😎😎
Beautiful
understood
Thanks a lot Bhaiya
update this video link on website
understood!
If someone is looking for a less redundant code:
class Solution:
def findMedianSortedArrays(self, nums1: List[int], nums2: List[int]) -> float:
n1,n2 = len(nums1),len(nums2)
n = n1+n2
ind1,ind2 = n//2-1,n//2
count = 0
i,j = 0,0
while i
how to make notes of these lectures?
what is time complexity of this solution ?,is it O(m+n) ? if yes then how to solve this in O(log(m)+log(n))?
The complexity you are mentioning is logm*n that is not asked
It's log(m+n)
🔥🔥🔥🔥🔥
fun fact in better approach : cnt is nothing but i + j
Understood
Bhai sahi mein tera questions ⁉️😅saarein galat hai 😅
understood
At 2:16 I thought I'd have to discard the common element 🤦🏻♂
Understand ❤🎉
Yay🤩
Do the code using O(1) space
Done
Public class solution {
Public static double median (int []a,int []b){
int m=a.length, n=b.length;
int i=0,j=0 m1=0,m2=0;
for(int count =0;count b[j]){
m1=b[j++];
}else {
m1=a[i++];
}
}
elseif(i
It seems like complicate to me
this is simple solution why complicated dryrun than understood
Bhaiya which topic will come next ?.....what are upcoming plans
@striver Why not put the OR condition in while loop instead of running while loop separately while merging the array? like
while(i< arr1.length || j < arr2.length){
thought the same!
❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
No BS
Bhai question to durr ki baat hai English thodi control mein kar 😢
Understood
understood
Understood
understood
Understood
understood
Understood
understood
Understood
Understood