BS-24. Search in a 2D Matrix - I | Binary Search of 2D

  Рет қаралды 86,053

take U forward

take U forward

Күн бұрын

Please watch our new video on the same topic: • BS-24. Search in a 2D ...
Check our Website:
Notes: • BS-24. Search in a 2D ...

Пікірлер: 99
@takeUforward
@takeUforward 11 ай бұрын
Please watch our new video on the same topic: kzbin.info/www/bejne/gIm4ZXShm9lqr80
@AbhishekSharma-ip4df
@AbhishekSharma-ip4df 11 ай бұрын
bhaiya..kya approach..kya intuition..kya energy..explain krne ka tareeka..legit sb awsm hota h aapka..u make us feel dsa🔥🔥
@prachigoyal2510
@prachigoyal2510 Жыл бұрын
A huge thanks Striver for putting all these efforts 🙏
@princebhanushali6255
@princebhanushali6255 2 ай бұрын
Best DSA questions and approaches among all the DSA tutorials on KZbin. Big thankss❤❤
@devkirandass7930
@devkirandass7930 Жыл бұрын
Striver is the best...Feel like worshipping him🥰
@SandeepM0ttan
@SandeepM0ttan 10 ай бұрын
Try kunal kushwaha then
@devkirandass7930
@devkirandass7930 10 ай бұрын
@@SandeepM0ttanyeah I know him....idk but I felt like he is too arrogant ....and he teaches JAVA and I am into C++
@cinime
@cinime 11 ай бұрын
Understood! Super wonderful explanation as always, thank you very very much!!
@sairam3351
@sairam3351 11 ай бұрын
You are excellent teacher bro,no professor comes close, 💖
@poonam-kamboj
@poonam-kamboj 10 ай бұрын
very nice and clearly explained , thanks for the good explanation!!
@jhanavikumari274
@jhanavikumari274 3 ай бұрын
you are definitely doing some sorcery out there like how can you make learning this interesting .
@hardikpatel352
@hardikpatel352 3 ай бұрын
Understood! Such a great explanation as always, thank you very much for your effort!!
@Gagansharma3002
@Gagansharma3002 6 ай бұрын
Bhai babbar ke to bus hype h asli udham to tumne machai h student ke learning me❤
@aswinsrikanth408
@aswinsrikanth408 10 ай бұрын
A great explanation as a whole bruh
@harshhwardhanrai3716
@harshhwardhanrai3716 Ай бұрын
at 10:15 I literally started searching for the intuition for it but thanks for explaining it :)
@theyashsawarkar
@theyashsawarkar 10 ай бұрын
very very helpfull explaination
@hareshnayak7302
@hareshnayak7302 4 ай бұрын
Understood,thanks striver for this amazing video.
@md.imrankhan6912
@md.imrankhan6912 11 ай бұрын
Thank You Mr Legend
@rushidesai2836
@rushidesai2836 2 ай бұрын
Amazing solution
@mrminus8590
@mrminus8590 Ай бұрын
Thanks for everything brother
@ayushagarwal5271
@ayushagarwal5271 Ай бұрын
coded it down myself! thanks!!
@ashishpradhan6250
@ashishpradhan6250 2 ай бұрын
amazing..thanku
@iampatelajeet
@iampatelajeet 11 ай бұрын
Thanks Bhaiya 💯❤
@iceyyeah
@iceyyeah 6 ай бұрын
You go crazy love that dude
@NazeerBashaShaik
@NazeerBashaShaik 3 ай бұрын
Understood, thank you.
@ArpanChakraborty-do6yz
@ArpanChakraborty-do6yz 5 ай бұрын
done and dusted❤‍🔥❤‍🔥just awesome
@shawshak2148
@shawshak2148 9 ай бұрын
understood thanks
@user-tk2vg5jt3l
@user-tk2vg5jt3l 5 ай бұрын
Thank you Bhaiya
@YourCodeVerse
@YourCodeVerse 7 ай бұрын
Understood✅🔥🔥
@EC20022ELAKKIYAC
@EC20022ELAKKIYAC 2 ай бұрын
Understood thank you
@harshitpatil6138
@harshitpatil6138 9 ай бұрын
Understoood✌✌👍👍
@ankanmalik409
@ankanmalik409 Жыл бұрын
dada make a video on - Divide two integers without using multiplication, division and mod operator
@chiragsharma8905
@chiragsharma8905 9 ай бұрын
My code with slightly more intuitive approach(according to me). O(log(n)+log(m)). Finding correct row first, and then finding target in that row. class Solution { public boolean searchMatrix(int[][] mat, int target) { int m = mat.length; if(m==0) return false; int lo = 0; int hi = m-1; while(lo
@saswatrath4646
@saswatrath4646 3 ай бұрын
great bhai same as my approach
@srujangajjala2658
@srujangajjala2658 Ай бұрын
log n + log m = log nm so time complexity is still same
@RajNamdev_19
@RajNamdev_19 Ай бұрын
@@srujangajjala2658 thanks for reminding me log formula I just forgot about it
@arihantjammar8888
@arihantjammar8888 11 ай бұрын
understood
@culeforever5408
@culeforever5408 9 ай бұрын
understood 😇
@KartikeyTT
@KartikeyTT 12 күн бұрын
tysm sir
@senseiAree
@senseiAree 9 ай бұрын
Understood ❤
@yatintripathi5638
@yatintripathi5638 11 ай бұрын
Hey Striver , I somehow find this question and Median in a row-wise sorted Matrix a bit similar , but my approach gets wrong when i try to flatten the matrix to find the median. Is my approach wrong towards the question?
@PrabhaKaran-36
@PrabhaKaran-36 3 ай бұрын
Understood❤
@RituSingh-ne1mk
@RituSingh-ne1mk 7 ай бұрын
Understood!
@nikhilkumarjamwal5322
@nikhilkumarjamwal5322 8 ай бұрын
It can also be done in O(n).
@Ajeetkumar-uo4hf
@Ajeetkumar-uo4hf 8 ай бұрын
Striver Energy OP !!
@artifice_abhi
@artifice_abhi 6 ай бұрын
but its not necessary that if my target lies within the range it will surely be there for eg if an array is: 3 6 7 8 and target is 5 so now I would apply binary search as it is within my range but actually its not present. And this can happen for the rows where every time target is within the range but not present there. So in worst case time complexity would be: N*log(M)
@harshilpatel3205
@harshilpatel3205 5 ай бұрын
No brother time complexity in the worst case stays as 0(n) + 0(log2(m)) ... Because once we find the answer we are returning the answer so it'll never go through each row...
@ShahNawaz-cx3pi
@ShahNawaz-cx3pi Ай бұрын
One more solution can be , first try to find out the correct row from 0th column (element in 0th column
@kundann_n9989
@kundann_n9989 10 күн бұрын
Can we not do a binary srach on i to look for the row that contains the target the do binary search on that row to look for target?
@suryasaimaheswar8636
@suryasaimaheswar8636 5 күн бұрын
understood :)
@abhishekprasad010
@abhishekprasad010 3 ай бұрын
Understood
@sarangkumarsingh7901
@sarangkumarsingh7901 2 ай бұрын
Understood...............
@harikakesharaju8799
@harikakesharaju8799 11 ай бұрын
Same code u submitted is giving me TLE error for me sir
@manikantachegu2182
@manikantachegu2182 16 күн бұрын
How about finding the row in which the element will be (by binary search ) and then applying binary search on the row can result in logn + logm crct me if im wrong because it worked for me in coding ninjas
@aradhyapandey1489
@aradhyapandey1489 8 ай бұрын
bhaiya...kitna bhayankar padhate ho🙏
@graviton001
@graviton001 3 күн бұрын
Solved myself ❤
@piyushmahale9024
@piyushmahale9024 Ай бұрын
❤❤❤❤
@lakshmanprabhu6722
@lakshmanprabhu6722 10 ай бұрын
Which is lesser time complexity, log(m) + log(n) , or log(m*n) ?
@rohitsai806
@rohitsai806 10 ай бұрын
both are same... log a + log b = log ab
@dayashankarlakhotia4943
@dayashankarlakhotia4943 11 ай бұрын
Optimal approach. Public class solution { static boolean Search in matrix( Array list mat,int target){ int m=mat.size(),n=mat.get(0).size (); int low=0, high =m*n -1; while (low
@sayantanpoddar5428
@sayantanpoddar5428 5 ай бұрын
Understood.............Understood!!!!! G.O.A.T
@shashankgsharma0901
@shashankgsharma0901 Ай бұрын
Understood, but please take m x n instead of n x m, took i / m the whole time taking m x n, so got segmentation fault the entire time.
@studyah
@studyah 3 ай бұрын
bhaiya why did you take log of base 2?
@saswatrath4646
@saswatrath4646 3 ай бұрын
search space is reducing by half everytime we are doing mid = (low +high)/2. Anytime if you are reducing your working space by diving something your time complexity becomes log base to diviser. Had we been doing mid = (low + high)/5, just imagine it, our time complexity would have been log base 5. Hope it helps!
@studyah
@studyah 3 ай бұрын
@@saswatrath4646 thanks for explaining:) But I can't grasp why it happens...why the time complexity becomes log of base of the divisor
@saswatrath4646
@saswatrath4646 3 ай бұрын
@@studyah Search space is reducing from N to N/2 to N/4 to N/8 and so on.. why so ? bcz we are doing eliminating one half either left of right from the mid according to our situation. before you read any further 2^k means 2 raised to the power k. Here is the detailed explanation buddy. You can also write N, N/2, N/4, N/8..... as N/2^0 , N/2^1, N/2^2, N/2^3.....let's say it goes till 2/2^K. N/2^K = 1 hoga right ? kyuki last me 1 element == target hoga. Solve the equation, N = 2^k hog. Recall the formula of log and exponential or search it on google, if N = 2 ^ K then K = log base 2 of N. Now if you observer we are going from 1 to K right ? when we were at 1 we considered the whole array, when we were at k we comsidered only a single element. So, we moved from 1, 2, 3,...K. K number of iterations, now what is K that we found out above ? log base 2 of N. Time complexity will be O(k) =O(log base 2 of N) .
@CodingJoySoul
@CodingJoySoul Жыл бұрын
Please help Indians become candidate masters on codeforces.
@rahulhembram4519
@rahulhembram4519 11 ай бұрын
UnderStood
@aniketdas4358
@aniketdas4358 6 ай бұрын
why am i getting runtime error with this code bool find(vector &arr,int col,int target) { int lo=0; int hi=col-1; while(lotarget) { hi=mid-1; } else if(arr[mid]
@saswatrath4646
@saswatrath4646 3 ай бұрын
when u r asking out do mention type or name of the error, it wil assist the person trying to help u out.
@saswatrath4646
@saswatrath4646 3 ай бұрын
change col to mat[i].size() and row to mat.size(), and write the col inside the for loop before calling bool function it will work perfectly fine.
@nakulchauhan6713
@nakulchauhan6713 6 ай бұрын
Your content and amount of effort is great. Huge respect for this course and you. But i feel you are not poking students to think, it appears as if you already know answer and here you are explaining it. Thought to process to come to a point should also be recorded. Lets say live solving DSA problems.
@Fe-ironman
@Fe-ironman 6 ай бұрын
You should watch this video only after going through the problems yourself
@dayashankarlakhotia4943
@dayashankarlakhotia4943 11 ай бұрын
BF approach. Public class { static boolean search matrix (Array list mat,int target){ int m=mat.size(), n=mat.get(0).size (); for(int i=0;i
@cenacr007
@cenacr007 10 ай бұрын
us
@pulamollavenkatreddy8162
@pulamollavenkatreddy8162 11 ай бұрын
Can we do this O( log(n)+ log(m)) by eliminating rows
@abhisheknag1929
@abhisheknag1929 11 ай бұрын
yes
@rohitsai806
@rohitsai806 10 ай бұрын
log(m) + log(n) = log(m*n) as per logarithms.. So both time complexities are same
@nayankhuman1043
@nayankhuman1043 7 күн бұрын
Understood ❤
@abhinanda7049
@abhinanda7049 10 ай бұрын
understood
@jasmeenjz
@jasmeenjz 3 ай бұрын
Understood
@chiragbansod8252
@chiragbansod8252 4 ай бұрын
understood
@KAMLESHSINGH-vr3bl
@KAMLESHSINGH-vr3bl 9 ай бұрын
understood
@shaiksoofi3741
@shaiksoofi3741 2 ай бұрын
understood
@shashankvashishtha4454
@shashankvashishtha4454 Ай бұрын
understood
@arnabkundu1648
@arnabkundu1648 2 ай бұрын
understood
@dewanandkumar8589
@dewanandkumar8589 3 ай бұрын
Understood
@sandeshgupta7950
@sandeshgupta7950 Ай бұрын
Understood
@ganeshvhatkar9253
@ganeshvhatkar9253 6 ай бұрын
Understood
@RajNamdev_19
@RajNamdev_19 Ай бұрын
Understood
@yrzwisdom
@yrzwisdom 29 күн бұрын
Understood
@user-nb1ye5tf1r
@user-nb1ye5tf1r 6 ай бұрын
Understood
@NARUTOUZUMAKI-bk4nx
@NARUTOUZUMAKI-bk4nx 6 ай бұрын
Understood
BS-25. Search in a 2D Matrix - II  |  Binary Search on 2D
15:29
take U forward
Рет қаралды 62 М.
SPILLED CHOCKY MILK PRANK ON BROTHER 😂 #shorts
00:12
Savage Vlogs
Рет қаралды 10 МЛН
Это реально работает?!
00:33
БРУНО
Рет қаралды 4 МЛН
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 7 МЛН
Launching the best DSA Course + Platform
36:29
take U forward
Рет қаралды 97 М.
Why UK 🇬🇧 is going Bankrupt? : Detailed Economic Case Study
20:37
Binary Search in 2D Arrays
58:57
Kunal Kushwaha
Рет қаралды 290 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
The Best Browsers for Privacy and Ad Blocking
8:40
Mental Outlaw
Рет қаралды 10 М.
5 Math Skills Every Programmer Needs
9:08
Sahil & Sarra
Рет қаралды 1 МЛН