BS-5. Search Element in Rotated Sorted Array II

  Рет қаралды 191,693

take U forward

take U forward

Күн бұрын

Пікірлер: 394
@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 10 ай бұрын
Understood. You are a genius.
@hardikpatel352
@hardikpatel352 7 ай бұрын
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 🙇🏿‍♂🙇🏿‍♂
@SumitSingh-dc8pm
@SumitSingh-dc8pm 11 ай бұрын
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 Ай бұрын
Understood! You are a savior to people who struggle in DSA (im one of them) and I cant thank you enough.
@lshuarckyma
@lshuarckyma Ай бұрын
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
@ArdentMusicLover
@ArdentMusicLover 4 күн бұрын
brilliantly explained, both part 1 and par 2. Thank you, Striver!
@LearnwithEase20
@LearnwithEase20 10 ай бұрын
Becoming your bigger fan day by day! Hats to your explanation
@momentcoder
@momentcoder 3 күн бұрын
Understood, solved the a2z sheet by 19%, thank you for the lovely content. 💌
@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
@reshmah1497
@reshmah1497 Ай бұрын
Really understood the concept. Thanks much for teaching very well.
@Anshydv3
@Anshydv3 Жыл бұрын
the best explaination , i have ever seen on binary Search , LOVE YOU BRO ❣
@depavathnareshnaik5584
@depavathnareshnaik5584 6 ай бұрын
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!
@anishaa3298
@anishaa3298 4 күн бұрын
the best explanation thus far
@stith_pragya
@stith_pragya 10 ай бұрын
UNDERSTOOD.........Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@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 3 ай бұрын
Really? Can you explain with an example?
@djinnGamingLive
@djinnGamingLive 2 ай бұрын
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.
@ravalik8611
@ravalik8611 10 күн бұрын
Heartful thanks to you bro......Your are doing a wonderful job by spreading the knowledge you have
@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!!
@HarshKumar-ip5nr
@HarshKumar-ip5nr Жыл бұрын
Understood the intuition and approach. Thanks for the series.
@prthms_
@prthms_ 10 ай бұрын
Understood.... Thank you so much for this wonderful Video❤❤
@prathambhushan4859
@prathambhushan4859 4 ай бұрын
didn't studied anyhing since last week, but starting again and gonna complete this in this week
@VikashKumar-tg3ot
@VikashKumar-tg3ot 7 ай бұрын
Understood very well,Now i able to code my self before watching solution.Thanks striver bro.
@vipinamar8323
@vipinamar8323 Күн бұрын
Awesome, your videos are a great resource. Thank you sir.
@darshilmodi6851
@darshilmodi6851 5 ай бұрын
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 5 ай бұрын
ur modification isnt working for ur test case bro
@srujangajjala2658
@srujangajjala2658 5 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
@@t3ch_r4id His Testcase is achivable by left rotating at 5th index
@monishamadu
@monishamadu 3 ай бұрын
It worked for me when I call the recursive method by just incrementing lower point, instead of continue.
@prajaktamhetre3010
@prajaktamhetre3010 Ай бұрын
best course and I just love ur videos
@AppaniMadhavi
@AppaniMadhavi 9 ай бұрын
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 7 ай бұрын
yup in leetcode, that edge case of 2 elements is covere [ 3, 1 ] here high crosses low
@nishanthcodes4576
@nishanthcodes4576 Жыл бұрын
This code complexity is O(N). I understand that, this is just to reinforce BS concept, but technically this becomes linear search. I would suggest, just reject the right part of array if the critical condition arrives. ie) if( ar[mid[ == ar[low] == ar[high]) then high = mid -1, simple.. now this code is O(logn). For people who can't get me (coz of my bad english).. Here is the code ( submitted and it passed all cases ): while(l=arr[l]){ if(k>=arr[l] && k=arr[m] && k
@jineshnadar6409
@jineshnadar6409 Жыл бұрын
Fails for [1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1] 2 you can't say that your mid + 1 to high will not contain the target just because the arr[ low ] == arr[ mid ] == arr[ high ] Target can be in left half or it can be right half depending on elements and rotations you've made
@simarpreetsingh7235
@simarpreetsingh7235 3 ай бұрын
​@@jineshnadar6409exactly, his code passed because of lesser test cases
@arunsagarsa3613
@arunsagarsa3613 6 ай бұрын
this guy is a gem! Nothing more to say.
@ramitroshan123
@ramitroshan123 16 күн бұрын
Thank you! for such an amazing explanation :)
@lakshmij6067
@lakshmij6067 8 ай бұрын
Understood bro, Thank you so much...Learning so much from your videos
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Most intuitive and well explained
@JK-de2gh
@JK-de2gh 4 ай бұрын
hatsoff to u mann...put some python code als...becoz some beginners will learn it in python....
@vijaynag7723
@vijaynag7723 11 ай бұрын
understood , thank you Striver.
@aakashsharma780
@aakashsharma780 2 ай бұрын
Again Understood Striver bhaiya ❤🔥🔥 , doing revision for placements..!!
@Sunil-ul1yg
@Sunil-ul1yg 4 ай бұрын
You are a legend bro!
@AtulKumar-c4x7l
@AtulKumar-c4x7l Жыл бұрын
understood Thank u Striver for a wonderful explanation
@mohithadiyal6083
@mohithadiyal6083 Жыл бұрын
THE best explanation
@Dipanshutripathi2407
@Dipanshutripathi2407 Жыл бұрын
Understood every part of the video.
@aakashsharma780
@aakashsharma780 Жыл бұрын
Understood Striver bhaiya ❤🙌
@yashraj5898
@yashraj5898 21 күн бұрын
understood , Great Exp. buddy !
@paragroy5359
@paragroy5359 11 ай бұрын
Great Content. Keep on making such videos.
@RIyaGupta-iz9iw
@RIyaGupta-iz9iw 7 ай бұрын
Best videos ever sir .. Understood
@brianjpeter9856
@brianjpeter9856 4 ай бұрын
Good Explanation Striver !
@champbehal8111
@champbehal8111 Жыл бұрын
Thnku striver❤
@abhinav_mittal
@abhinav_mittal 4 ай бұрын
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 4 ай бұрын
and i might add using sort(arr.begin(), arr.end()); function in the starting of the code
@umangagarwal8726
@umangagarwal8726 4 ай бұрын
​@@abhinav_mittal why in this question we cant return index and just returning true false?
@abhinav_mittal
@abhinav_mittal 4 ай бұрын
@@umangagarwal8726 because in question it says to return true if found and false if not found
@umangagarwal8726
@umangagarwal8726 4 ай бұрын
@@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 4 ай бұрын
@@umangagarwal8726 yes but I think in the interview they can ask to solve using another method so that's why
@infinitecodes
@infinitecodes Жыл бұрын
Understood 😊
@adarshagarwal9508
@adarshagarwal9508 6 ай бұрын
amazing waiting for the strings sums
@per.seus._
@per.seus._ Жыл бұрын
UNDERSTOOD❤
@chirag71269
@chirag71269 Ай бұрын
Understood Striver ❤
@prasannamalatesha3887
@prasannamalatesha3887 Жыл бұрын
Great video, wonderful job explaining bro!!
@ramujanak963
@ramujanak963 Жыл бұрын
yes its understood striver 💙
@kingbadshah452
@kingbadshah452 10 ай бұрын
understood everything thanks striver!!!!
@KR_Technical-hj3bf
@KR_Technical-hj3bf Ай бұрын
i can say one thing about you that no one dislike you
@priyanshunautiyal1662
@priyanshunautiyal1662 8 ай бұрын
Understood bhaiya ❤
@culeforever5408
@culeforever5408 Жыл бұрын
understood
@Alwayspowerstar143
@Alwayspowerstar143 9 ай бұрын
Understood Striver👌
@myproject6768
@myproject6768 Жыл бұрын
Absolutely understand ❤
@infernogamer52
@infernogamer52 Жыл бұрын
Understood Bhaiya!
@muditsinghal6042
@muditsinghal6042 3 ай бұрын
What i did was simply trim one side down in starting, for example for 1 1 1 2 2 2 1 1 1, check if nums[0] is target, if not left++ until nums[left !]= nums[right], this will make it, 2 2 1 1 1 , now do the search
@charchitagarwal589
@charchitagarwal589 3 ай бұрын
This will make the time complexity o( n )
@muditsinghal6042
@muditsinghal6042 3 ай бұрын
@@charchitagarwal589 no because we check if the array is sorted or not, only if it isn't sorted this will implement
@charchitagarwal589
@charchitagarwal589 3 ай бұрын
@@muditsinghal6042 yeah o(n) is worst case time complexity
@mehrabhossain8225
@mehrabhossain8225 11 ай бұрын
best explanation bro
@RaghavN-rd5zw
@RaghavN-rd5zw 7 ай бұрын
Understood!!! Thanks striver!!!
@ashokbabug40
@ashokbabug40 Жыл бұрын
Amazing video bro really appreciated
@manishchahar9110
@manishchahar9110 9 ай бұрын
Amazing work bro, keep rocking
@ayushirastogi9725
@ayushirastogi9725 Жыл бұрын
understood love the course!!!
@NazeerBashaShaik
@NazeerBashaShaik 7 ай бұрын
Understood, thank you.
@shrirambalaji2915
@shrirambalaji2915 Жыл бұрын
Understood and you are awesome brother...
@samuelfrank1369
@samuelfrank1369 Жыл бұрын
Understood. Thanks a lot.
@tanmaychaudhary2801
@tanmaychaudhary2801 Жыл бұрын
Thank you so much bhaiya ❤😇🙏
@Integral_MC
@Integral_MC Ай бұрын
understood, thanks
@anuragprasad6116
@anuragprasad6116 10 ай бұрын
To solve this in O(log N), we can use if (arr[mid] == arr[high]) high = mid-1; That is, if arr[mid]==arr[high] we can be sure that the complete right half has elements = arr[mid] and it can be safely discarded.
@simarpreetsingh7235
@simarpreetsingh7235 3 ай бұрын
Nope 11111111211 Your logic will fail here
@amitjindar6706
@amitjindar6706 3 ай бұрын
UNDERSTOOD
@amityadav-np1rk
@amityadav-np1rk Жыл бұрын
Great explanation!!
@SAHIL-dq8je
@SAHIL-dq8je Жыл бұрын
Thanks bhaiya
@utsavseth6573
@utsavseth6573 Жыл бұрын
Great lecture .
@selene8721
@selene8721 3 ай бұрын
Thank you so much!
@CodeMode9313
@CodeMode9313 Жыл бұрын
shukriya habibi
@rahulpathak859
@rahulpathak859 Жыл бұрын
Understood everything💯
@humanity7880
@humanity7880 Жыл бұрын
understood!
@RaunitJaiswal-s9v
@RaunitJaiswal-s9v 2 ай бұрын
You know what life is too unpredictable not for everyone but for few it is
@oyeesharme
@oyeesharme 3 ай бұрын
understood bhaiya
@motivatewithme123
@motivatewithme123 3 ай бұрын
STRIVER BHAII 💌
@lakshminarayana5500
@lakshminarayana5500 Жыл бұрын
Understood
@nagavedareddy5891
@nagavedareddy5891 Жыл бұрын
Thank u striver... ❤
@ESkp15
@ESkp15 Жыл бұрын
Wow! Understood!
@Liftedmonk
@Liftedmonk 9 ай бұрын
buddy is a god
@abhisarsahay8136
@abhisarsahay8136 3 ай бұрын
understood striver!!!!
@RaviKumar-sn6tu
@RaviKumar-sn6tu 7 ай бұрын
Understood sir ...
@Bug-g5b
@Bug-g5b 4 күн бұрын
ty striver!
@arjitgautam365
@arjitgautam365 Жыл бұрын
well explained. Appreciated
@ujjawalraj6096
@ujjawalraj6096 Жыл бұрын
Understood everything
@YourCodeVerse
@YourCodeVerse 11 ай бұрын
Understood✅🔥🔥
@David-kj7el
@David-kj7el 5 ай бұрын
so the only problem is in the case of (arr[low] == arr[mid] == arr[high]) for that we do nothing just do low++ and high-- (that is trimming down the search space) one of the way to handle duplicates
@JothiprakashThangaraj
@JothiprakashThangaraj 4 ай бұрын
understood!!!! thanks a lot!
@shivanshchaturvedi2601
@shivanshchaturvedi2601 Жыл бұрын
Thanku
@Learnprogramming-q7f
@Learnprogramming-q7f 9 ай бұрын
Thank you bhaiya
@shubhamsharma-nb8yd
@shubhamsharma-nb8yd Жыл бұрын
Instead of continue , you can change next if to else if ... that will also work :P
@music-loverFam
@music-loverFam 3 ай бұрын
Understood☺
@ritikasingh5443
@ritikasingh5443 2 ай бұрын
thank you sir
@RAJSINGH-mr7hq
@RAJSINGH-mr7hq Жыл бұрын
Superb. Understood!!
@sahulraj9536
@sahulraj9536 9 ай бұрын
i followed a different approach for the special case if nums[low] == nums[mid] == nums[high] then i checked if mid to high is sorted but i checked it using linear search.
BS-6. Minimum in Rotated Sorted Array
17:08
take U forward
Рет қаралды 193 М.
BS-4. Search Element in Rotated Sorted Array - I
16:38
take U forward
Рет қаралды 292 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН
Farmer narrowly escapes tiger attack
00:20
CTV News
Рет қаралды 11 МЛН
Search in Rotated Sorted Array II - Leetcode 81 - Python
17:36
NeetCodeIO
Рет қаралды 17 М.
BS-8. Single Element in Sorted Array
22:16
take U forward
Рет қаралды 173 М.
Search in rotated sorted array - Leetcode 33 - Python
13:28
NeetCode
Рет қаралды 364 М.
BS-13. Minimum days to make M bouquets | Binary Search
26:01
take U forward
Рет қаралды 153 М.
BS-12. Koko Eating Bananas
21:04
take U forward
Рет қаралды 187 М.
BS-24. Search in a 2D Matrix - I | Binary Search of 2D
15:42
take U forward
Рет қаралды 116 М.
The Ultimate Sausage Prank! Watch Their Reactions 😂🌭 #Unexpected
00:17
La La Life Shorts
Рет қаралды 8 МЛН