BS-5. Search Element in Rotated Sorted Array II

  Рет қаралды 221,201

take U forward

take U forward

Күн бұрын

Problem Link: bit.ly/3MCdLTY
Notes/C++/Java/Python codes: takeuforward.o...
We have solved the problem, and we have gone from brute force and ended with the most optimal solution. Every approach's code has been written in the video itself. Also, we have covered the algorithm with intuition.
Full Course: bit.ly/tufA2ZYt
You can follow me across social media, all my handles are below:
Linkedin/Instagram/Telegram: linktr.ee/take...
0:00 Introduction of Course

Пікірлер: 423
@takeUforward
@takeUforward Жыл бұрын
Please comment understood and give us a like if you got everything :)
@FactFactoryCentral
@FactFactoryCentral Жыл бұрын
In this code, isn't the worst case O(N). If all elements are same, and the element to be searched is not there in the array. Example: [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3], target: 4 Is O(N) the best that can be done if we have duplicate elements ?
@sudhanshushekhar4222
@sudhanshushekhar4222 Жыл бұрын
understood
@venup2813
@venup2813 Жыл бұрын
Understood
@abhisheksinghmehra9576
@abhisheksinghmehra9576 Жыл бұрын
Understood
@365tage9
@365tage9 Жыл бұрын
Understood. You are a genius.
@lshuarckyma
@lshuarckyma 3 ай бұрын
TIP BY STRIVER AT THE END: if you get questions envolving duplicates then try to solve them as unique element based and modify the code where the condition fails , for ex here it breaks at identifying the sorting portion
@SumitSingh-dc8pm
@SumitSingh-dc8pm Жыл бұрын
You just are a legend. Hat's off to you man. Loved your content. You start from basics and made this concept a cakewalk. Huge Respect for you.
@Mr.Manoj1
@Mr.Manoj1 3 ай бұрын
Understood! You are a savior to people who struggle in DSA (im one of them) and I cant thank you enough.
@hardikpatel352
@hardikpatel352 9 ай бұрын
there are lots of paid courses are available and many are upcoming but none of them is such in-depth and free like striver's A to Z dsa , Thanks a lot raj sir 🙇🏿‍♂🙇🏿‍♂
@LearnwithEase20
@LearnwithEase20 Жыл бұрын
Becoming your bigger fan day by day! Hats to your explanation
@mehulthuletiya497
@mehulthuletiya497 Жыл бұрын
Time-Stamps: 00:32 Problem Statement 00:50 Recap: Search Element in Rotated Sorted Array I 01:28 Why this problem different from previous 05:38 Explanation & Approach Start (Search Element in Rotated Sorted Array II) 10:09 Code 10:19 Complexity 11:41 Tip to solve problem
@Anshydv3
@Anshydv3 Жыл бұрын
the best explaination , i have ever seen on binary Search , LOVE YOU BRO ❣
@reshmah1497
@reshmah1497 3 ай бұрын
Really understood the concept. Thanks much for teaching very well.
@depavathnareshnaik5584
@depavathnareshnaik5584 8 ай бұрын
Thank you for the excellent instruction on BS. Your clear explanations and engaging teaching methods really helped me grasp the concepts thoroughly. I feel much more confident in my understanding now. I appreciate your dedication and support!
@stith_pragya
@stith_pragya Жыл бұрын
UNDERSTOOD.........Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@ArdentMusicLover
@ArdentMusicLover 2 ай бұрын
brilliantly explained, both part 1 and par 2. Thank you, Striver!
@ManishKumar-kw7qe
@ManishKumar-kw7qe Ай бұрын
This question is really a good one.!!! if you are not able to solve,it 's fine because it's not a typical binary search
@momentcoder
@momentcoder 2 ай бұрын
Understood, solved the a2z sheet by 19%, thank you for the lovely content. 💌
@HarshKumar-ip5nr
@HarshKumar-ip5nr Жыл бұрын
Understood the intuition and approach. Thanks for the series.
@venkatsaireddy1412
@venkatsaireddy1412 Жыл бұрын
You are always the best bro, Thank you for clear explanation.
@cinime
@cinime Жыл бұрын
Understood! Wonderful explanation as always, thank you very very much for your continuous effort!!
@anishaa3298
@anishaa3298 2 ай бұрын
the best explanation thus far
@prthms_
@prthms_ Жыл бұрын
Understood.... Thank you so much for this wonderful Video❤❤
@ravalik8611
@ravalik8611 2 ай бұрын
Heartful thanks to you bro......Your are doing a wonderful job by spreading the knowledge you have
@darshilmodi6851
@darshilmodi6851 8 ай бұрын
I truly appreciate your detailed explanation! To contribute to the community's knowledge, I encountered a situation where the original logic using low++ and high-- to handle duplicates wouldn't work. Here's a specific test case that demonstrates the issue: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1]. Fortunately, a simple fix exists. Instead of decrementing both low and high, we can simply increment low like this: low++. This modification allows the code to function correctly.
@srujangajjala2658
@srujangajjala2658 8 ай бұрын
ur modification isnt working for ur test case bro
@srujangajjala2658
@srujangajjala2658 8 ай бұрын
there is some error in coding ninjas, i ran the same code in offline compiler with ur test case it returned true only, in coding ninjas its returning false
@t3ch_r4id
@t3ch_r4id 6 ай бұрын
I have submitted the code in coding ninja successfully the problem is if you carefully observe the question it states that array will be right rotated not left rotated 💡
@aishezsingh7004
@aishezsingh7004 6 ай бұрын
@@t3ch_r4id His Testcase is achivable by left rotating at 5th index
@monishamadu
@monishamadu 5 ай бұрын
It worked for me when I call the recursive method by just incrementing lower point, instead of continue.
@VikashKumar-tg3ot
@VikashKumar-tg3ot 9 ай бұрын
Understood very well,Now i able to code my self before watching solution.Thanks striver bro.
@rumiNITPatna
@rumiNITPatna Ай бұрын
thank you so much striver ! u made me love dsa.
@prajaktamhetre3010
@prajaktamhetre3010 3 ай бұрын
best course and I just love ur videos
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Most intuitive and well explained
@vipinamar8323
@vipinamar8323 2 ай бұрын
Awesome, your videos are a great resource. Thank you sir.
@prathambhushan4859
@prathambhushan4859 7 ай бұрын
didn't studied anyhing since last week, but starting again and gonna complete this in this week
@ErenYeager-dp4er
@ErenYeager-dp4er 29 күн бұрын
Done on 11 Jan 2025 at 18:44 Place : Study Room 2, Hostel 5, IIT Bombay
@photon7404
@photon7404 20 күн бұрын
what you ate before doing and which brand's pc . kidding. good job bro .
@lakshmij6067
@lakshmij6067 10 ай бұрын
Understood bro, Thank you so much...Learning so much from your videos
@arunsagarsa3613
@arunsagarsa3613 9 ай бұрын
this guy is a gem! Nothing more to say.
@Sunil-ul1yg
@Sunil-ul1yg 7 ай бұрын
You are a legend bro!
@KR_Technical-hj3bf
@KR_Technical-hj3bf 4 ай бұрын
i can say one thing about you that no one dislike you
@infinitecodes
@infinitecodes Жыл бұрын
Understood 😊
@aakashsharma780
@aakashsharma780 4 ай бұрын
Again Understood Striver bhaiya ❤🔥🔥 , doing revision for placements..!!
@akbunofficial1281
@akbunofficial1281 Жыл бұрын
Better way to avoid the edge case of arr[mid]=arr[low]=arr[high] is to check the right sorted first , this will make the code more efficient
@manusklm1161
@manusklm1161 5 ай бұрын
Really? Can you explain with an example?
@djinnGamingLive
@djinnGamingLive 4 ай бұрын
I don't think that will work. Even if we check the right sorted list first we need to know about the order of the first, middle and last element before that so we can rule out the possibility of them being equal.
@JK-de2gh
@JK-de2gh 7 ай бұрын
hatsoff to u mann...put some python code als...becoz some beginners will learn it in python....
@ramitroshan123
@ramitroshan123 3 ай бұрын
Thank you! for such an amazing explanation :)
@AtulKumar-c4x7l
@AtulKumar-c4x7l Жыл бұрын
understood Thank u Striver for a wonderful explanation
@per.seus._
@per.seus._ Жыл бұрын
UNDERSTOOD❤
@AppaniMadhavi
@AppaniMadhavi Жыл бұрын
The code for the rotated sorted array I is also worked for rotated sorted array II in coding ninjas, but coding ninjas didn't provided all edge test cases.
@harshvardhansankpal716
@harshvardhansankpal716 9 ай бұрын
yup in leetcode, that edge case of 2 elements is covere [ 3, 1 ] here high crosses low
@vijaynag7723
@vijaynag7723 Жыл бұрын
understood , thank you Striver.
@mohithadiyal6083
@mohithadiyal6083 Жыл бұрын
THE best explanation
@RIyaGupta-iz9iw
@RIyaGupta-iz9iw 10 ай бұрын
Best videos ever sir .. Understood
@brianjpeter9856
@brianjpeter9856 6 ай бұрын
Good Explanation Striver !
@ayushirastogi9725
@ayushirastogi9725 Жыл бұрын
understood love the course!!!
@yashraj5898
@yashraj5898 3 ай бұрын
understood , Great Exp. buddy !
@champbehal8111
@champbehal8111 Жыл бұрын
Thnku striver❤
@paragroy5359
@paragroy5359 Жыл бұрын
Great Content. Keep on making such videos.
@prasannamalatesha3887
@prasannamalatesha3887 Жыл бұрын
Great video, wonderful job explaining bro!!
@kingbadshah452
@kingbadshah452 Жыл бұрын
understood everything thanks striver!!!!
@nice_random_guy5347
@nice_random_guy5347 6 күн бұрын
understood! Thanks!
@RaghavN-rd5zw
@RaghavN-rd5zw 9 ай бұрын
Understood!!! Thanks striver!!!
@Dipanshutripathi2407
@Dipanshutripathi2407 Жыл бұрын
Understood every part of the video.
@aakashsharma780
@aakashsharma780 Жыл бұрын
Understood Striver bhaiya ❤🙌
@amityadav-np1rk
@amityadav-np1rk Жыл бұрын
Great explanation!!
@ashokbabug40
@ashokbabug40 Жыл бұрын
Amazing video bro really appreciated
@RaviKumar-sn6tu
@RaviKumar-sn6tu 10 ай бұрын
Understood sir ...
@rahulpathak859
@rahulpathak859 Жыл бұрын
Understood everything💯
@YourCodeVerse
@YourCodeVerse Жыл бұрын
Understood✅🔥🔥
@adarshagarwal9508
@adarshagarwal9508 9 ай бұрын
amazing waiting for the strings sums
@shrirambalaji2915
@shrirambalaji2915 Жыл бұрын
Understood and you are awesome brother...
@samuelfrank1369
@samuelfrank1369 Жыл бұрын
Understood. Thanks a lot.
@NazeerBashaShaik
@NazeerBashaShaik 10 ай бұрын
Understood, thank you.
@manishchahar9110
@manishchahar9110 Жыл бұрын
Amazing work bro, keep rocking
@myproject6768
@myproject6768 Жыл бұрын
Absolutely understand ❤
@priyanshunautiyal1662
@priyanshunautiyal1662 10 ай бұрын
Understood bhaiya ❤
@mehrabhossain8225
@mehrabhossain8225 Жыл бұрын
best explanation bro
@JothiprakashThangaraj
@JothiprakashThangaraj 7 ай бұрын
understood!!!! thanks a lot!
@anshikajain7990
@anshikajain7990 8 ай бұрын
Understood😊😊🎉
@tanmaychaudhary2801
@tanmaychaudhary2801 Жыл бұрын
Thank you so much bhaiya ❤😇🙏
@ramujanak963
@ramujanak963 Жыл бұрын
yes its understood striver 💙
@selene8721
@selene8721 6 ай бұрын
Thank you so much!
@arjitgautam365
@arjitgautam365 Жыл бұрын
well explained. Appreciated
@nagavedareddy5891
@nagavedareddy5891 Жыл бұрын
Thank u striver... ❤
@mangeshgupta7095
@mangeshgupta7095 Ай бұрын
Big thanks ❤
@Liftedmonk
@Liftedmonk 11 ай бұрын
buddy is a god
@utsavseth6573
@utsavseth6573 Жыл бұрын
Great lecture .
@harshalparanjiya5850
@harshalparanjiya5850 27 күн бұрын
let's go --> 13 january 🔥🔥
@Ryugaz1
@Ryugaz1 4 ай бұрын
understood, thanks
@chirag71269
@chirag71269 4 ай бұрын
Understood Striver ❤
@infernogamer52
@infernogamer52 Жыл бұрын
Understood Bhaiya!
@ESkp15
@ESkp15 Жыл бұрын
Wow! Understood!
@RamkumarB-k5r
@RamkumarB-k5r 22 күн бұрын
Understood anna...!
@deeptidip9864
@deeptidip9864 Жыл бұрын
Understood 💯
@knox9450
@knox9450 Жыл бұрын
Understood❤
@RAJSINGH-mr7hq
@RAJSINGH-mr7hq Жыл бұрын
Superb. Understood!!
@humanity7880
@humanity7880 Жыл бұрын
understood!
@Alwayspowerstar143
@Alwayspowerstar143 11 ай бұрын
Understood Striver👌
@bhavesh_baraiya21
@bhavesh_baraiya21 8 ай бұрын
understood!🙂
@motivatewithme123
@motivatewithme123 6 ай бұрын
STRIVER BHAII 💌
@CodeBoost8375
@CodeBoost8375 Жыл бұрын
Understood 😃
@culeforever5408
@culeforever5408 Жыл бұрын
understood
@amitjindar6706
@amitjindar6706 6 ай бұрын
UNDERSTOOD
@-ShangsitNath
@-ShangsitNath 9 ай бұрын
Worst case time complexity will become O(n) ?? Eg. if array = [3,3,3,3,3,3,3,3], target = 1 ??
@kushwanthkapa2041
@kushwanthkapa2041 7 ай бұрын
Yup😊
@manusklm1161
@manusklm1161 5 ай бұрын
Nope...it's n/2
@EerieEntertainment-mc4ce
@EerieEntertainment-mc4ce 5 ай бұрын
@@manusklm1161 O(n/2) is also order of n
@manusklm1161
@manusklm1161 5 ай бұрын
@@EerieEntertainment-mc4ce yeah I too know that we won't consider constants .but first we should able to find as precisely as possible, right and then you can do that stuff like neglecting constants etc.
@abhinav_mittal
@abhinav_mittal 6 ай бұрын
we can just use regular binary array and return true; in place of return m; if(arr[m] == target) and in the ending we can return false; rather then return -1;
@abhinav_mittal
@abhinav_mittal 6 ай бұрын
and i might add using sort(arr.begin(), arr.end()); function in the starting of the code
@umangagarwal8726
@umangagarwal8726 6 ай бұрын
​@@abhinav_mittal why in this question we cant return index and just returning true false?
@abhinav_mittal
@abhinav_mittal 6 ай бұрын
@@umangagarwal8726 because in question it says to return true if found and false if not found
@umangagarwal8726
@umangagarwal8726 6 ай бұрын
@@abhinav_mittal yeah I know that but striver says in this question you cant return index using binary search that's why I am asking why this? As just remove true false and return mid or -1 it will give index
@abhinav_mittal
@abhinav_mittal 6 ай бұрын
@@umangagarwal8726 yes but I think in the interview they can ask to solve using another method so that's why
@Bug-g5b
@Bug-g5b 2 ай бұрын
ty striver!
@hallupandet228
@hallupandet228 Жыл бұрын
Understood💥
@mohamedriffath5781
@mohamedriffath5781 Жыл бұрын
Greatwork
@abhay9994
@abhay9994 Жыл бұрын
Thank you.
@Karthik-ep6en
@Karthik-ep6en 9 ай бұрын
understood 👍
BS-6. Minimum in Rotated Sorted Array
17:08
take U forward
Рет қаралды 223 М.
BS-4. Search Element in Rotated Sorted Array - I
16:38
take U forward
Рет қаралды 338 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
My scorpion was taken away from me 😢
00:55
TyphoonFast 5
Рет қаралды 2,7 МЛН
How to Stop Procrastinating and Finally Take Action
16:31
Ali Abdaal
Рет қаралды 133 М.
BS-17. Aggressive Cows | Binary Search Hard
26:44
take U forward
Рет қаралды 205 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 568 М.
BS-8. Single Element in Sorted Array
22:16
take U forward
Рет қаралды 199 М.
Maximum Product Subarray - Best Intuitive Approach Discussed
20:27
take U forward
Рет қаралды 270 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН