BS-5. Search Element in Rotated Sorted Array II

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ • 395

  • @takeUforward
    @takeUforward  Рік тому +75

    Please comment understood and give us a like if you got everything :)

    • @FactFactoryCentral
      @FactFactoryCentral Рік тому +8

      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 11 місяців тому

      Understood. You are a genius.

  • @hardikpatel352
    @hardikpatel352 7 місяців тому +22

    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 місяців тому +24

    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.

  • @LearnwithEase20
    @LearnwithEase20 10 місяців тому +4

    Becoming your bigger fan day by day! Hats to your explanation

  • @ArdentMusicLover
    @ArdentMusicLover 8 днів тому

    brilliantly explained, both part 1 and par 2. Thank you, Striver!

  • @lshuarckyma
    @lshuarckyma Місяць тому +4

    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

  • @reshmah1497
    @reshmah1497 Місяць тому +1

    Really understood the concept. Thanks much for teaching very well.

  • @stith_pragya
    @stith_pragya 10 місяців тому +2

    UNDERSTOOD.........Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @momentcoder
    @momentcoder 7 днів тому

    Understood, solved the a2z sheet by 19%, thank you for the lovely content. 💌

  • @anishaa3298
    @anishaa3298 8 днів тому

    the best explanation thus far

  • @Anshydv3
    @Anshydv3 Рік тому +2

    the best explaination , i have ever seen on binary Search , LOVE YOU BRO ❣

  • @ravalik8611
    @ravalik8611 14 днів тому

    Heartful thanks to you bro......Your are doing a wonderful job by spreading the knowledge you have

  • @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!

  • @venkatsaireddy1412
    @venkatsaireddy1412 Рік тому +3

    You are always the best bro, Thank you for clear explanation.

  • @cinime
    @cinime Рік тому +2

    Understood! Wonderful explanation as always, thank you very very much for your continuous effort!!

  • @prthms_
    @prthms_ 10 місяців тому +1

    Understood.... Thank you so much for this wonderful Video❤❤

  • @prajaktamhetre3010
    @prajaktamhetre3010 Місяць тому

    best course and I just love ur videos

  • @Mr.Manoj1
    @Mr.Manoj1 Місяць тому +4

    Understood! You are a savior to people who struggle in DSA (im one of them) and I cant thank you enough.

  • @HarshKumar-ip5nr
    @HarshKumar-ip5nr Рік тому +2

    Understood the intuition and approach. Thanks for the series.

  • @vipinamar8323
    @vipinamar8323 5 днів тому

    Awesome, your videos are a great resource. Thank you sir.

  • @VikashKumar-tg3ot
    @VikashKumar-tg3ot 7 місяців тому

    Understood very well,Now i able to code my self before watching solution.Thanks striver bro.

  • @mehulthuletiya497
    @mehulthuletiya497 Рік тому +19

    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

  • @arunsagarsa3613
    @arunsagarsa3613 6 місяців тому

    this guy is a gem! Nothing more to say.

  • @Sunil-ul1yg
    @Sunil-ul1yg 4 місяці тому +1

    You are a legend bro!

  • @lakshmij6067
    @lakshmij6067 8 місяців тому

    Understood bro, Thank you so much...Learning so much from your videos

  • @darshilmodi6851
    @darshilmodi6851 6 місяців тому +4

    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.

  • @akbunofficial1281
    @akbunofficial1281 Рік тому +3

    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.

  • @prathambhushan4859
    @prathambhushan4859 5 місяців тому

    didn't studied anyhing since last week, but starting again and gonna complete this in this week

  • @ramitroshan123
    @ramitroshan123 21 день тому

    Thank you! for such an amazing explanation :)

  • @aakashsharma780
    @aakashsharma780 2 місяці тому

    Again Understood Striver bhaiya ❤🔥🔥 , doing revision for placements..!!

  • @RIyaGupta-iz9iw
    @RIyaGupta-iz9iw 8 місяців тому

    Best videos ever sir .. Understood

  • @mohithadiyal6083
    @mohithadiyal6083 Рік тому

    THE best explanation

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Рік тому +1

    Most intuitive and well explained

  • @AtulKumar-c4x7l
    @AtulKumar-c4x7l Рік тому

    understood
    Thank u Striver for a wonderful explanation

  • @per.seus._
    @per.seus._ Рік тому +1

    UNDERSTOOD❤

  • @paragroy5359
    @paragroy5359 11 місяців тому

    Great Content.
    Keep on making such videos.

  • @JK-de2gh
    @JK-de2gh 4 місяці тому +1

    hatsoff to u mann...put some python code als...becoz some beginners will learn it in python....

  • @RaghavN-rd5zw
    @RaghavN-rd5zw 7 місяців тому

    Understood!!! Thanks striver!!!

  • @AppaniMadhavi
    @AppaniMadhavi 9 місяців тому +1

    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

  • @brianjpeter9856
    @brianjpeter9856 4 місяці тому

    Good Explanation Striver !

  • @yashraj5898
    @yashraj5898 25 днів тому

    understood , Great Exp. buddy !

  • @aakashsharma780
    @aakashsharma780 Рік тому

    Understood Striver bhaiya ❤🙌

  • @vijaynag7723
    @vijaynag7723 11 місяців тому

    understood , thank you Striver.

  • @infinitecodes
    @infinitecodes Рік тому +1

    Understood 😊

  • @prasannamalatesha3887
    @prasannamalatesha3887 Рік тому

    Great video, wonderful job explaining bro!!

  • @shrirambalaji2915
    @shrirambalaji2915 Рік тому

    Understood and you are awesome brother...

  • @ayushirastogi9725
    @ayushirastogi9725 Рік тому

    understood love the course!!!

  • @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 Рік тому +2

      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

  • @kingbadshah452
    @kingbadshah452 10 місяців тому

    understood everything thanks striver!!!!

  • @ashokbabug40
    @ashokbabug40 Рік тому

    Amazing video bro really appreciated

  • @priyanshunautiyal1662
    @priyanshunautiyal1662 8 місяців тому

    Understood bhaiya ❤

  • @myproject6768
    @myproject6768 Рік тому

    Absolutely understand ❤

  • @Dipanshutripathi2407
    @Dipanshutripathi2407 Рік тому

    Understood every part of the video.

  • @manishchahar9110
    @manishchahar9110 9 місяців тому

    Amazing work bro, keep rocking

  • @rahulpathak859
    @rahulpathak859 Рік тому

    Understood everything💯

  • @Liftedmonk
    @Liftedmonk 9 місяців тому

    buddy is a god

  • @abhinav_mittal
    @abhinav_mittal 4 місяці тому +1

    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

  • @champbehal8111
    @champbehal8111 Рік тому +1

    Thnku striver❤

  • @samuelfrank1369
    @samuelfrank1369 Рік тому

    Understood. Thanks a lot.

  • @amityadav-np1rk
    @amityadav-np1rk Рік тому

    Great explanation!!

  • @infernogamer52
    @infernogamer52 Рік тому

    Understood Bhaiya!

  • @ESkp15
    @ESkp15 Рік тому

    Wow! Understood!

  • @YourCodeVerse
    @YourCodeVerse 11 місяців тому

    Understood✅🔥🔥

  • @RAJSINGH-mr7hq
    @RAJSINGH-mr7hq Рік тому

    Superb. Understood!!

  • @NazeerBashaShaik
    @NazeerBashaShaik 7 місяців тому

    Understood, thank you.

  • @mehrabhossain8225
    @mehrabhossain8225 11 місяців тому

    best explanation bro

  • @adarshagarwal9508
    @adarshagarwal9508 6 місяців тому

    amazing waiting for the strings sums

  • @motivatewithme123
    @motivatewithme123 3 місяці тому

    STRIVER BHAII 💌

  • @KCOYASH
    @KCOYASH Рік тому

    UnderStood :) and thanks for such great videos ..

  • @hallupandet228
    @hallupandet228 Рік тому

    Understood💥

  • @culeforever5408
    @culeforever5408 Рік тому +1

    understood

  • @deeptidip9864
    @deeptidip9864 Рік тому

    Understood 💯

  • @amitjindar6706
    @amitjindar6706 3 місяці тому

    UNDERSTOOD

  • @ramujanak963
    @ramujanak963 Рік тому

    yes its understood striver 💙

  • @-ShangsitNath
    @-ShangsitNath 7 місяців тому +2

    Worst case time complexity will become O(n) ?? Eg. if array = [3,3,3,3,3,3,3,3], target = 1 ??

    • @kushwanthkapa2041
      @kushwanthkapa2041 5 місяців тому

      Yup😊

    • @manusklm1161
      @manusklm1161 3 місяці тому

      Nope...it's n/2

    • @EerieEntertainment-mc4ce
      @EerieEntertainment-mc4ce 3 місяці тому

      @@manusklm1161 O(n/2) is also order of n

    • @manusklm1161
      @manusklm1161 3 місяці тому

      @@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.

  • @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

  • @chirag71269
    @chirag71269 Місяць тому

    Understood Striver ❤

  • @knox9450
    @knox9450 Рік тому

    Understood❤

  • @JothiprakashThangaraj
    @JothiprakashThangaraj 5 місяців тому

    understood!!!! thanks a lot!

  • @Alwayspowerstar143
    @Alwayspowerstar143 9 місяців тому

    Understood Striver👌

  • @utsavseth6573
    @utsavseth6573 Рік тому

    Great lecture .

  • @isoindia2061
    @isoindia2061 Рік тому

    Understood!

  • @ItsIshahere
    @ItsIshahere 7 місяців тому

    Understood !!! :)

  • @selene8721
    @selene8721 3 місяці тому

    Thank you so much!

  • @mohamedriffath5781
    @mohamedriffath5781 Рік тому

    Greatwork

  • @arjitgautam365
    @arjitgautam365 Рік тому

    well explained. Appreciated

  • @anshikajain7990
    @anshikajain7990 6 місяців тому

    Understood😊😊🎉

  • @srinathv1412
    @srinathv1412 9 місяців тому

    Understood !!!!!

  • @tanmaychaudhary2801
    @tanmaychaudhary2801 Рік тому +1

    Thank you so much bhaiya ❤😇🙏

  • @humanity7880
    @humanity7880 Рік тому +1

    understood!

  • @singhji4149
    @singhji4149 Рік тому

    Nice one striver as usual

  • @hrithikgoswami9808
    @hrithikgoswami9808 Рік тому

    Understood!!

  • @anonymousofficial7824
    @anonymousofficial7824 Рік тому

    Understood!

  • @pihus3498
    @pihus3498 Рік тому

    understooood :)

  • @raunakkumarmishra1449
    @raunakkumarmishra1449 Рік тому

    Understood❤

  • @AbhishekBhattacharjee-j2m
    @AbhishekBhattacharjee-j2m Рік тому

    UNDERSTOOD

  • @nagavedareddy5891
    @nagavedareddy5891 Рік тому

    Thank u striver... ❤

  • @RaviKumar-sn6tu
    @RaviKumar-sn6tu 8 місяців тому

    Understood sir ...

  • @anirbanghosh9611
    @anirbanghosh9611 Рік тому +2

    Instead of using if and continue can we also use a while loop for it

    • @nikhilneela
      @nikhilneela Рік тому

      It does not matter from a complexity standpoint.

  • @CodeMode9313
    @CodeMode9313 Рік тому

    shukriya habibi