Тёмный

Search A 2D Sorted Matrix - Fundamentals of Search Space Reduction 

Back To Back SWE
Подписаться 240 тыс.
Просмотров 51 тыс.
50% 1

Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe.com/pricing
📹 Intuitive Video Explanations
🏃 Run Code As You Learn
💾 Save Progress
❓New Unseen Questions
🔎 Get All Solutions
Question: There are 2 versions.
Version 1: Every row is sorted left to right in non-decreasing order. The first integer of each row is greater or equal to the last integer of the previous row.
Version 2: Every row is sorted left to right in non-decreasing order. Every column is sorted top to bottom in non-decreasing order. There are no guarantees that the first item of any row or column relates to the last item in the previous row or column.
Sorted. Binary search is very likely. Investigate, how do we reduce our decision space?
Our first answer does not need to be logarithmic (it is so crucial you understand logarithms and what they mean....you need to know your complexities to refine answers and notice avenues to better solutions).
The key to search problems is that you notice the fundamental decision we can make to reduce the problem.
...more notes I wrote...
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: / @hackerrankofficial
Tuschar Roy: / tusharroy2525
GeeksForGeeks: / @geeksforgeeksvideos
Jarvis Johnson: / vsympathyv
Success In Tech: / @successintech

Наука

Опубликовано:

 

8 мар 2019

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 265   
@BackToBackSWE
@BackToBackSWE 5 лет назад
Table of Contents: The Problem Introduction (Variant 1) 0:00 - 1:51 Jumping To The Brute Force 1:51 - 2:52 Optimizing Our Search 2:52 - 4:14 We Need To Notice Something... 4:14 - 5:49 The Data Does Not Dictate How We Interpret It 5:49 - 7:28 Establishing Our Mapping System 7:28 - 11:03 Executing The Binary Search 11:03 - 15:10 Runtime of Our Binary Search 15:10 - 15:45 The Problem Introduction (Variant 2) 15:45 - 16:43 Jumping To The Brute Force 16:43 - 17:15 The #1 Key To Search Problems 17:15 - 19:08 Defining Our Fundamental Decision Operation 19:08 - 20:57 Searching For Places To Start Our Search 20:57 - 22:48 Search Example #1 (Bottom Left Starting Point) 22:48 - 24:37 Search Example #2 (Top Right Starting Point) 24:37 - 25:38 What Just Happened 25:38 - 26:19 Analyzing Our Incremental Approach 26:19 - 28:34 Wrap Up 28:34 - 29:11 The code for both variants is in the description, fully commented for understanding purposes.
@JulianBG
@JulianBG 4 года назад
At ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-FOa55B9Ikfg.html the complexity is between O(n) and O(log(n)), because the real "n" is n*m and using binary search on each row will be faster than O(n), where n are all numbers.
@BackToBackSWE
@BackToBackSWE 4 года назад
I don't remember this video well enough to have a comment
@hamzaahmad1224
@hamzaahmad1224 Год назад
Hi! I can't seem to locate the code
@gradientO
@gradientO Год назад
As a beginner, this channel is such a goldmine. The way you explain complex topics in a easy intuitive way is really amazing wow man
@BackToBackSWE
@BackToBackSWE Год назад
Thank you! Please enjoy a special code from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=madmax 🎉
@yusefmustafa2603
@yusefmustafa2603 5 лет назад
Just got my FB swe intern offer yesterday! Your vids help out a ton man.
@darod6098
@darod6098 5 лет назад
I will have my FB interview next week. Is it ok if I send a message to you?
@yusefmustafa2603
@yusefmustafa2603 5 лет назад
@@darod6098 go for it
@darod6098
@darod6098 5 лет назад
@@yusefmustafa2603 youtu.be/addme/-QH9AgDdeiTXzl3HYqC3bGJdfw4zYQ
@BackToBackSWE
@BackToBackSWE 5 лет назад
nice, good job :) keep it up
@satyajitkamble1646
@satyajitkamble1646 5 лет назад
Hey Yusef! Can I connect with you!? I am applying to FB as well within 3 weeks and i need some guidance!
@joshhwb
@joshhwb 4 года назад
Astounded this has < 10k views. By far the best content on these topics I've come across. Keep grinding Ben!
@BackToBackSWE
@BackToBackSWE 4 года назад
say no more
@saadtajwar2105
@saadtajwar2105 3 года назад
Haven't commented on a coding explanation video before but this is actually the best channel ever. I was struggling so hard with this problem until this video and this made everything seem so easy. Thank you so much, please never stop creating this amazing content.
@ishanshah3309
@ishanshah3309 3 года назад
He has a magic of explaining dsa problems very well.
@BackToBackSWE
@BackToBackSWE 3 года назад
thanks
@liyingyin9845
@liyingyin9845 4 года назад
Oh man!!! You are awesome!!! Lots people can write perfect code but not many of them can express their ideas and especially make others understand the code and why write the code this way.. but you MADE IT!!!! "Reducing the search space." You are genius!!! Thanks for all your hard working!!!
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks haha
@kharinskiyalexey7409
@kharinskiyalexey7409 5 лет назад
"Reducing the search space..." - such a nice insight! Thanks man your lessons made me more confident.
@BackToBackSWE
@BackToBackSWE 5 лет назад
nice.
@gssnhimabindu8831
@gssnhimabindu8831 4 года назад
Whenever I can't understand any question and see that you have done a video on it already .. I feel so relieved!! Thanks for such awesome videos! Could you also make videos on how should we present the solution to questions asked in coding interviews ?
@BackToBackSWE
@BackToBackSWE 4 года назад
great - sure - I can't due to time constraints but we have backtobackswe.com (paywall)
@som_girl6702
@som_girl6702 Год назад
Same, makes learning fun!
@bubsterbrandino6365
@bubsterbrandino6365 2 года назад
Just stumbled upon this video and have to say youre one of the best teachers for computer science I have seen.
@BackToBackSWE
@BackToBackSWE 2 года назад
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@ravipatel-xu5qi
@ravipatel-xu5qi 3 года назад
It took so much time for me to find someone on youtube like you who can explain in so much depth. There are lots of channels who explains the direct solutions but those are not really helping. You are the real hero who helps us to build the correct logic. Thank you so much. Keep making such good videos.
@sachitmohannayak4964
@sachitmohannayak4964 3 года назад
This is spectacular! So clear and concise - bonus it covers the variant too!
@bendevenport7221
@bendevenport7221 5 лет назад
Keep doing what you're doing... please. You're so clear on explanations and without showing me code, I'm understanding the concepts of these questions so much more now. I wish I stumbled on these sooner. I'm actively applying right now as a graduating senior. I am not having much luck landing interviews due in part to my lack of an internship... but I'm hoping going through these practices will help me slam dunk whatever interview comes my way some day. Thank you!
@BackToBackSWE
@BackToBackSWE 5 лет назад
Hahahaha. Yes. This project is still very much active (as long as people demonstrate interest). We will continue to expand.
@aprajitajha9195
@aprajitajha9195 4 года назад
The solution feels effortless once I have been through your videos! Thanks so much! :)
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@charan775
@charan775 4 года назад
dude I have read many tutorials and discussions on this question but no one has actually explained why we choose top right or bottom left like you did. you're just awesome man
@BackToBackSWE
@BackToBackSWE 4 года назад
no u
@farizma
@farizma 3 года назад
This channel has best explainations, the way he approaches, starts from brute-force, slowly move to optimal with clearly explaining each move, makes coding feel very easy. Love the contents. plz dont't stop, keep making the videos, of-course this channel can become the world's largest swe resource.
@wl7497
@wl7497 5 лет назад
Of course it's helpful, you can influence lots of people and they benefited from your instructions. Keep it up, bro!
@BackToBackSWE
@BackToBackSWE 5 лет назад
I will.
@nastusalmander
@nastusalmander 4 года назад
Hey, I've been watching your videos and they're very helpful for studying for interviews. You do some really clever things that I won't have thought of and I appreciated opening my perspective. Granted these problems weren't be done while I'm working at a SWE job but to get that job these types of videos are needed. Much love and best wishes in the future
@BackToBackSWE
@BackToBackSWE 4 года назад
Sure
@piyushmajgawali1611
@piyushmajgawali1611 4 года назад
The second variant was asked in Amazon coding test
@BackToBackSWE
@BackToBackSWE 4 года назад
Nice
@ramjiintrouble
@ramjiintrouble 2 года назад
You are just amazing Ben ! Thanks for covering both the variants !
@michalbelay8540
@michalbelay8540 2 года назад
The best algorithms guy in youtube, thank you!
@farshadsaberi2740
@farshadsaberi2740 2 года назад
Great explanation! Thank you!
@khssameernew
@khssameernew 4 года назад
Sir, Your videos are AWESOME , nothing can be better than this!!! ... could you please do some videos on system design problems.....
@BackToBackSWE
@BackToBackSWE 4 года назад
yeah, we will find someone for that
@mp0157
@mp0157 4 года назад
The most beautiful and all-encompassing explanation of this problem solving approach on the internet! :) Your videos help a lot! Please keep up the good work Ben!
@BackToBackSWE
@BackToBackSWE 4 года назад
nice yo
@cristianouzumaki2455
@cristianouzumaki2455 2 года назад
One of the best explanations or walkthroughs I have ever seen for any problem.
@BackToBackSWE
@BackToBackSWE 2 года назад
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@Hasansaid51
@Hasansaid51 4 года назад
I’m glad I found your RU-vid channel last night cuz I’ve been stuck on this problem for a while lol. 🙏🏾
@BackToBackSWE
@BackToBackSWE 4 года назад
welcome
@shakawatabsar9984
@shakawatabsar9984 4 года назад
Carry on, bro. Your algo video is really different and effective than the other guys on the youtube. Others just give the solution but you are the one who tries to explain the reasons behind the solution.
@BackToBackSWE
@BackToBackSWE 4 года назад
ok - carrying on
@MohitSinha4
@MohitSinha4 4 года назад
Your videos are really awesome! Thanks for helping!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure - flourish
@goodwish1543
@goodwish1543 4 года назад
Excellent elaboration! It is systematic and a easy to climb learning curve.
@BackToBackSWE
@BackToBackSWE 4 года назад
nice
@raninagare7678
@raninagare7678 4 года назад
You are a really awesome man:). I was afraid of these problems before, but once you explained the logic, I am so much confident now. If you continue to teach like this, no one can stop you from being the world's largest and best software engineering resource.
@BackToBackSWE
@BackToBackSWE 4 года назад
ye, lez do it
@tolulopemalomo8922
@tolulopemalomo8922 Год назад
Thank you so much for this video!
@spk9434
@spk9434 5 лет назад
awesome as always. Best spent 29 minutes of the day ! Do a video on spiral matrix.
@BackToBackSWE
@BackToBackSWE 5 лет назад
hahahaha, sure. And I only take suggestions from Patrons who support the project now. To be fair to those paying to support the project
@parvezmulla3324
@parvezmulla3324 4 года назад
Amazing!. You explained the detail thought process.
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@SigalGraboys
@SigalGraboys 3 года назад
really helpful!!! thank you
@RahulVerma-fz2jf
@RahulVerma-fz2jf 4 года назад
Awesome !!. I think, today I understood both the approaches in depth. Won't forget now. :). Keep up the good work.
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@abdoulbarry8111
@abdoulbarry8111 3 года назад
The king is so good at this I wonder where he gets his knowledge!!! I swear this is the best class anyone can take
@DonTaldo
@DonTaldo 3 года назад
As always, awesome content
@JacobAbraham-twozerosix
@JacobAbraham-twozerosix 5 лет назад
Nice.... Really enjoying this... Your presentation has improved... Keep up the good work.
@BackToBackSWE
@BackToBackSWE 5 лет назад
I know.
@praison9104
@praison9104 4 года назад
Thanks for the great explanation as always!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@rishbhardwaj1431
@rishbhardwaj1431 5 лет назад
The last bit is genius! I figured I can't reduce my search space when I started at the top left, but it just didn't strike me that the top right or bottom left would work.
@BackToBackSWE
@BackToBackSWE 5 лет назад
nice
@sidhant4674
@sidhant4674 5 лет назад
Great explanation man!
@BackToBackSWE
@BackToBackSWE 5 лет назад
thanks
@chenpeng2797
@chenpeng2797 5 лет назад
Thanks a lot for your teaching!
@BackToBackSWE
@BackToBackSWE 5 лет назад
Sure, it's nothing
@amadousallah8916
@amadousallah8916 5 лет назад
Your explanation is amazing. Thanks
@BackToBackSWE
@BackToBackSWE 5 лет назад
thanks
@user-oy4kf5wr8l
@user-oy4kf5wr8l 3 года назад
This video is the most genius video ever! Super super good buddy!! we love u!!!
@BackToBackSWE
@BackToBackSWE 3 года назад
no love u go internet
@user-oy4kf5wr8l
@user-oy4kf5wr8l 3 года назад
@@BackToBackSWE what r u talking about buddy 🤣
@yicai7
@yicai7 4 года назад
Awesome! Really appreciate it bro!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@abhinaygupta
@abhinaygupta 3 года назад
Brilliant Explaination 👍🏻
@cpaniaguam
@cpaniaguam 2 года назад
I like your emphasis on the fundamentals. The fundamentals!
@BackToBackSWE
@BackToBackSWE 2 года назад
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@karantiwari9328
@karantiwari9328 4 года назад
I don't know why I didn't find your channel sooner. Thank you so much for this explanation!!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@iamrigank
@iamrigank 4 года назад
You are doing great man. Keep it up!
@BackToBackSWE
@BackToBackSWE 4 года назад
ok
@akshaygarg576
@akshaygarg576 3 года назад
Best explanation I ever heard. You taught to help us build mental model. You are awesome
@BackToBackSWE
@BackToBackSWE 3 года назад
thx
@RockingFrom86
@RockingFrom86 4 года назад
I've literally stopped doing office work this corona season. I log in, finish stand-up and come here :P This is fascinating stuff !!
@BackToBackSWE
@BackToBackSWE 4 года назад
great
@calculusvideos1760
@calculusvideos1760 3 года назад
Awesome explanation!
@BackToBackSWE
@BackToBackSWE 3 года назад
thx
@deardeer_czl
@deardeer_czl 4 года назад
really enjoy this video!
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@radtrav1
@radtrav1 3 года назад
Thanks for the videos as always . You’re the man
@BackToBackSWE
@BackToBackSWE 3 года назад
sure
@praveenchouhan6388
@praveenchouhan6388 4 года назад
super explaination!!! keep up the work, thanks :-)
@BackToBackSWE
@BackToBackSWE 4 года назад
ok. thanks.
@melvinabraham159
@melvinabraham159 4 года назад
Excellent content!
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@JG-zu6nq
@JG-zu6nq 5 лет назад
Been watching your vids and got my Amazon interview next week. Hopefully goes well!
@BackToBackSWE
@BackToBackSWE 5 лет назад
2 people messaged me and said they got in Amazon after peeping the vids...you got this :)
@JG-zu6nq
@JG-zu6nq 5 лет назад
@@BackToBackSWE Just got my offer. Thanks a bunch man, keep up the great work!
@BackToBackSWE
@BackToBackSWE 5 лет назад
@@JG-zu6nq nice, good luck at your new job!
@drashtisahu3598
@drashtisahu3598 3 года назад
You are the Best Sir ! Thank you so much
@hamdyahmed1984
@hamdyahmed1984 4 года назад
Hi Ben, please keep going on, you will change the industry soon. Thank you very much for your efforts.
@BackToBackSWE
@BackToBackSWE 4 года назад
ok
@saianuhyakodimela4267
@saianuhyakodimela4267 4 года назад
great explanation! very clear
@BackToBackSWE
@BackToBackSWE 4 года назад
thankls
@islamkadri7159
@islamkadri7159 3 года назад
@@BackToBackSWE just when i thought you had a bot making all these replies. lol
@vasachisenjubean5944
@vasachisenjubean5944 4 года назад
such an informative video. thanks boss
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@Hav0c1000
@Hav0c1000 4 года назад
Wow! Thank you for the easier method of solving the variant... I think at one point I understood the more complicated solution... but I have already forgot... and there is no way its going to come to me during high pressure interview... This method is very intuitive!
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@naveenverma2390
@naveenverma2390 5 лет назад
you are great man , really doing good job , i paused the video in between to comment this
@BackToBackSWE
@BackToBackSWE 4 года назад
nice
@ekejma
@ekejma 3 года назад
Another great video even if I know the answer there is always something I missed or under thought in terms of a deeper exploration of the problem space.
@TheSteak1984
@TheSteak1984 3 года назад
Thank you!
@Messirobben047
@Messirobben047 3 года назад
God-level explanation!
@pranavnyavanandi9710
@pranavnyavanandi9710 2 года назад
This channel will be real big one day.
@sagarshah8390
@sagarshah8390 3 года назад
beautiful explanation
@charliel7041
@charliel7041 4 года назад
always helpful in my LeetCode learning!!!!!!!!!!!!!!!!!!!!!!!
@BackToBackSWE
@BackToBackSWE 4 года назад
Great to hear - we want to create something better than Leetcode one day
@princekumarsingh5345
@princekumarsingh5345 4 года назад
very detailed lecture. Thanks for the content
@BackToBackSWE
@BackToBackSWE 4 года назад
sure
@pranayshah44
@pranayshah44 4 года назад
AWESOME! Thank you. Just subscribed ;)
@BackToBackSWE
@BackToBackSWE 4 года назад
sure thanks and nice
@joycewu4806
@joycewu4806 3 года назад
sorted great point!!!
@abhishekgautam1063
@abhishekgautam1063 4 года назад
Amazing!! Can't be better.
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks.
@zubairzafar480
@zubairzafar480 Год назад
Subscribed in first 10 seconds. Amazing content.
@BackToBackSWE
@BackToBackSWE Год назад
Thanks, appreciate it 😄 We'd love for you to check out our Free 5 Day DSA Interview Prep Mini-Course - backtobackswe.com/ 🎉
@derilraju2106
@derilraju2106 5 лет назад
You deserve lot more views on your videos!
@BackToBackSWE
@BackToBackSWE 5 лет назад
thx
@kartikeydixit3743
@kartikeydixit3743 4 года назад
Really appreciate how much effort this man takes to explain everything easily
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@kartikeydixit3743
@kartikeydixit3743 4 года назад
Hey can you provide the code for this
@shreyshekhar6419
@shreyshekhar6419 3 года назад
12:03 We need to do our Math: opens the marker cap. Nah the animation guy will take care of it XD. Btw awesome video bud as always!
@VishalKumar-kr9me
@VishalKumar-kr9me 4 года назад
Love you man...You are the best
@BackToBackSWE
@BackToBackSWE 4 года назад
no u
@adarshjadhav8877
@adarshjadhav8877 3 года назад
Hats off to ur explanation brother.. Beginners look for quick solutions and might skip ur vedio.. but believe me eventually they will follow u to learn the thought processs.....
@BackToBackSWE
@BackToBackSWE 3 года назад
thanks
@nikita12351
@nikita12351 3 года назад
Good stuff.
@satyajitkamble1646
@satyajitkamble1646 5 лет назад
You doin a great job man!! :-)
@BackToBackSWE
@BackToBackSWE 5 лет назад
thx
@Official-tk3nc
@Official-tk3nc 4 года назад
best explanation ever seen:)
@BackToBackSWE
@BackToBackSWE 4 года назад
thx
@khushalvyas5633
@khushalvyas5633 4 года назад
No one could explain it better than you
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@kellyxiao3060
@kellyxiao3060 5 лет назад
You are amazing and really like your video.
@BackToBackSWE
@BackToBackSWE 5 лет назад
thanks
@arnabchakraborty246
@arnabchakraborty246 4 года назад
Grt grt grt video.. Grt thinking power
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks haha
@remyb9937
@remyb9937 5 лет назад
Hey what's up! I actually just got past the HC at Google! I spent about 5 weeks almost exclusively studying your videos (and Tushar Roy's along with some others) and doing Leetcode problems (I actually had that much time), and went onto my onsite and did pretty well. I pulled off the design interview, but would love to see a video or two on Software Design Interviews. Thanks again!
@BackToBackSWE
@BackToBackSWE 5 лет назад
NICE! Wait...so you got hired? Or is there another step past hiring committee? I'm not fully familiar with the final steps. Also, check back in a little...I have plans...I'm launching a Patreon and have more announcements.
@remyb9937
@remyb9937 5 лет назад
@@BackToBackSWE HC is pretty much hired they told me. They are just looking for a team placement. I think it varies from person to person though whether HC is the last step, but they indicated for me it was the last as far as problem s solving is concerned. Anywho, I'm still super into your stuff and will keep following it. I think I'm going to do competetivel coding as a hobby! You've really inspired me!
@BackToBackSWE
@BackToBackSWE 5 лет назад
@@remyb9937 Nice! I was considering that route (competitive programming), but I don't think I'd be willing to dedicate the time to get really good...and I like talking better haha. Connect with me on LinkedIn if you want, let's stay in touch.
@Raj_Patel21
@Raj_Patel21 5 лет назад
Awesome...!!!
@BackToBackSWE
@BackToBackSWE 5 лет назад
hey
@sebastianacostamolina9593
@sebastianacostamolina9593 11 месяцев назад
God bless, i love your energy
@mohakchaudhary1981
@mohakchaudhary1981 5 лет назад
Bestest explanation ⚡🎉🎈🎈😀
@BackToBackSWE
@BackToBackSWE 5 лет назад
yoyo
@aayush9080
@aayush9080 5 лет назад
I've really liked your way of explaining It would be of great help to me if you create videos on system design Please
@BackToBackSWE
@BackToBackSWE 5 лет назад
I will eventually, I am not an expert in that so I need to learn first before I can authoritatively teach that. It is in high demand amongst people.
@haifzhan
@haifzhan 3 года назад
Valuable tutorial, thanks! Where's the coding solution? It was mentioned in the description but I didn't find it.
@kenilpatel7841
@kenilpatel7841 4 года назад
I wish I could like the video more than once!
@BackToBackSWE
@BackToBackSWE 4 года назад
lol
@timmy610387
@timmy610387 4 года назад
You're the best ^^
@BackToBackSWE
@BackToBackSWE 4 года назад
no u
@sachinsaini1806
@sachinsaini1806 4 года назад
YOU ARE GOD, buddy this channel is very very very impressive and your explanation skills are just over the top, i am sure i will see you in Google someday :)
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks ha.
@sunilsarode4295
@sunilsarode4295 4 года назад
superb ....:)
@BackToBackSWE
@BackToBackSWE 4 года назад
thanks
@mohinim.1654
@mohinim.1654 4 года назад
You are geniusssss
@BackToBackSWE
@BackToBackSWE 4 года назад
im normal
@briarsmith8241
@briarsmith8241 3 года назад
Something that everyone seems to be missing that makes this problem a lot easier is that arrays and vectors are contiguous in memory. This means that you can just increment, so if there is 4 columns and you are at row 1, the index 4 (the start of the second row) can be accessed by simply doing array[4]. Just continue this from 0 to n*m. Much easier than messing around with the modulus and division.
@michaelhernandez5478
@michaelhernandez5478 3 года назад
Hey, really great explanation on exploiting the properties of a 2d matrix. One part I couldn't follow was at 14:21 , you calculate the midpoint at row 1 col 2. And the target value is greater than the midpoint. Did you mean to say "go to the right"?
@justpk5773
@justpk5773 4 года назад
As row heads are sorted as well, why dont u do binary search on Row heads to find out which exact row to search & then within that row u can do binary search. Assuming m rows & n columns, it can be done in O(log m) + O(log n)
@BackToBackSWE
@BackToBackSWE 4 года назад
im not sure I dont remember this problem's details too well
@BarneyBing883
@BarneyBing883 4 года назад
Hey, thanks for the video. I came up with another solution that runs in log(m) + log(n) time. Don't know whether that's faster than log(mn). So the solution is - 1. We know each row is sorted. 2. We know each row is "contiguously" sorted, so that the last element of each row is less than or equal to the first element of the next row. 3. That means the first column would also be sorted. 4. So we do a binary search on just the first column. If the element is found, good; else, we can at least locate the row where the element would be. We just need to terminate our binary search when we get to a row where the first element is less than the element, and the next row's first element is greater than the element. This is log(m). 5. Then just do a binary search on this row. That's log(n). Think this works, but I'm not sure if that's faster than log(mn).
@BackToBackSWE
@BackToBackSWE 4 года назад
Yes, that sounds like a valid solution and is logarithmic. Edit (revising original answer): log(m) + log(n) is the same as log(m*n) by logarithm rules. Either way, both approaches are asymptotically the same.
@BarneyBing883
@BarneyBing883 4 года назад
@@BackToBackSWE Thanks! Your videos are a boon, by the way.
@BackToBackSWE
@BackToBackSWE 4 года назад
@@BarneyBing883 nice
Далее
BS-27. Median in a Row Wise Sorted Matrix
23:13
Просмотров 80 тыс.
The moment we stopped understanding AI [AlexNet]
17:38
Просмотров 879 тыс.
SpaceX Drops Big Starship Flight 5 News!
21:03
Просмотров 396 тыс.
PS2 с OLED экраном - Anbernic RG556
20:54
Просмотров 27 тыс.
Странные СБОРКИ Windows 2
23:25
Просмотров 28 тыс.
Открываем домофоны с Mi Band 9
0:59
Просмотров 182 тыс.
КАКОЙ SAMSUNG КУПИТЬ В 2024 ГОДУ
14:59