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.
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
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.
@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){
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
Please watch our new video on the same topic: ruclips.net/video/F9c7LpRZWVQ/видео.html
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.
This better approach is pretty smart I must say. Array is visualized just using two variables, amazing.
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!!
बहुत सही गुरु जी जलवा है आपका 😂
UnderStood, Wanted to learn this from a long long time.
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 :(
What a brilliant approach!!!
If You do this bruteforce in Pyhton language then your all test cases will pass
python is really good language
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 bro ...........But still having O(N+M) time complexity. Need further improvements.
Thank You Much for this wonderful video...................🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
understood, thanks for the perfect explanation
Thanks for the detailed explanation
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.
where was binary search in this problem striver?
Me thinking of that too.
Ain't this normal array question???
watch the optimal solution dude
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)
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
its still giving partially accepted
Do the code using O(1) space
Understood
Understood!
Understood✅🔥🔥
Thank you Bhaiya
update this video link on website
Beautiful
Understood, thank you.
UNDERSTOOD
Bhaiya which topic will come next ?.....what are upcoming plans
Thanks a lot Bhaiya
understood!
"here comes the twist"
Understood !! 😎😎
Understood
understood
Bhai sahi mein tera questions ⁉️😅saarein galat hai 😅
@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!
understood
Understand ❤🎉
fun fact in better approach : cnt is nothing but i + j
🔥🔥🔥🔥🔥
Done
At 2:16 I thought I'd have to discard the common element 🤦🏻♂
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
Yay🤩
❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
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
Bhai question to durr ki baat hai English thodi control mein kar 😢
No BS
Understood
understood
Understood
Understood
Understood
Understood
Understood
understood
understood
understood