BS-4. Search Element in Rotated Sorted Array - I

Поделиться
HTML-код
  • Опубликовано: 8 ноя 2024

Комментарии • 463

  • @takeUforward
    @takeUforward  Год назад +139

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

  • @yash-seth
    @yash-seth Год назад +34

    God tier explanation. I truly can't put in words how easily and clearly you were able to explain a seemingly confusing question!

  • @chaudharyalisha7175
    @chaudharyalisha7175 Год назад +24

    No wonder how demotivated I was when I saw that question and was looking for a good explanation since last 7 days (no, not even exaggerating). But, this man is love!!! Keep going @Striver :) You're our hope!!

  • @hilal937
    @hilal937 Год назад +9

    I was struggling with Binary search on sorted array for a long time,
    Your key point "Eliminate one half" has cleared my confusion.
    Thank you so much Striver

  • @abhisheksinghmehra9576
    @abhisheksinghmehra9576 Год назад +185

    We never move backward bcoz we have Take You Forward😇

  • @reyanshmishra7676
    @reyanshmishra7676 Год назад +16

    The best explanation I have found for this problem.
    Alog is very simple now
    1. Identity the sorted half.
    2. Check if the target lies in the sorted half.
    Thats it you need to do this two things only.

    • @alwinsanthosh6878
      @alwinsanthosh6878 Месяц назад

      Ig after solving like 15 BS problems, that's somewhat how all BS qs probably are.
      Divide search space into two halves
      Use some condition to eliminate either of the half from the search space

  • @monstercoder3665
    @monstercoder3665 Год назад +70

    None can compete with this man....!!! Simply amazing 👏. Great Work Striver Bhaiyya
    #DSA ka baap.
    The best thing about you is that you are not paid and spreading knowledge to all the aspirants...

    • @iamnoob7593
      @iamnoob7593 Год назад +3

      I think people should pay for this next level quality content.

    • @shubhamkumar-hx1fb
      @shubhamkumar-hx1fb Год назад

      @@iamnoob7593 haa...if u wish to.. then plss donate that money to some nearby ngos.

  • @mehulthuletiya497
    @mehulthuletiya497 Год назад +37

    00:24 Problem statement
    01:06 Example
    01:43 Solution-01 (Linear Search)
    02:21 Solution-02 (Binary Search)
    05:00 Dry-run
    11:42 Pseudocode
    15:17 Code
    15:28 Complexity

  • @junaidahmed3615
    @junaidahmed3615 Год назад +7

    what an absolutely great explanation. i watched another video before this and it was so convoluted for no reason. yours is so simple and easy to grasp

  • @knownforunknowns
    @knownforunknowns 7 дней назад +1

    The one who are selling just their courses and making abundant money are getting more and more fame and heavily recognised today, but the person who truly creating impact is just not even known by everyone today, But anyway thank u so much striver bhaiya , for this great quality content , i wish you will be respected by every cs student of india one day !!

  • @beingproductive22
    @beingproductive22 9 месяцев назад +7

    here after love babar lec - 14 for rotated sorted array he is using the concept of pivot element which is little messy
    but striver what a lovely lovely explanation
    in 1 go i understood and coded it myself

    • @Josuke217
      @Josuke217 3 месяца назад +1

      I learned recursion stack and queues from him , he's not a good teacher .

    • @sarveshkulkarni6287
      @sarveshkulkarni6287 2 месяца назад

      Yep that's not intuitive as this the striver's approach is

  • @sergion_brayen
    @sergion_brayen 8 месяцев назад +3

    honestly I was very confused and demotivated after watching Rohit negi sir's explanation in paid course , i spent 2 hour to understand this problem but could not get it , after watching strivers explanation i get it only after single iteration. thanks a lot . now i am going to follow strivers AtoZ DSA

  • @lofireverbz-wy7go
    @lofireverbz-wy7go Год назад +54

    09:56 seriously i watched this many times to see your expression 😄

    • @yoongicorn7973
      @yoongicorn7973 Год назад +7

      Yeah and The little smile when he continued... so cute ❤

    • @lofireverbz-wy7go
      @lofireverbz-wy7go Год назад

      that,s nice on which lecture you are currently
      @@yoongicorn7973

    • @shivanipatwa4709
      @shivanipatwa4709 2 месяца назад +1

      yk striver is a cutie....😉😉

    • @Akshitrawat121
      @Akshitrawat121 Месяц назад +1

      Mujhe mera mele m khoya hua bhai mil gya because our thoughts are same 🤣

  • @unknown2003august
    @unknown2003august 4 месяца назад +3

    Notes for me☺
    As we get our mid at any index checks arr[num]==target if it satisfies return here.
    After that
    Case 1>
    Array is left sorted(we check it by standing on mid),
    ==>Checks where our target lies in sorted(between low to mid ) or outside it by using
    if(arr[low]=target)
    if it lies inside this it indicates we need to collapse window by taking high to mid -1 otherwise low to mid+1
    Case 2>
    Array is right sorted similarly we check for it and updates our low and high accordingly
    if we never get it we return -1 to it

  • @ML-ok9nf
    @ML-ok9nf Год назад +2

    One of the best explanations for this problem on the internet!

  • @venkatsaireddy1412
    @venkatsaireddy1412 9 месяцев назад +1

    Thank You Raj Vikramaditya.
    I am a scaler student , i fond of Your teaching skills more than scaler instructors.

  • @pratikkumarsingh8114
    @pratikkumarsingh8114 Год назад +2

    Understood bhaiya , thw way of teching is another level, I don't have words to express my feelings. Thanks a lot, bhaiya!!!

  • @venkatesasrikanthdhulipala9486
    @venkatesasrikanthdhulipala9486 Год назад +3

    one small correction in the code it will fail if the array is [3,1] and target = 1
    because of code in line no 9 i.e k

    • @sarveshkulkarni6287
      @sarveshkulkarni6287 2 месяца назад

      No wrong, let me proove , low = 0 , high = 1 , mid = 0 , Now check if arr[low]

  • @junaiid0104
    @junaiid0104 4 месяца назад +1

    crazy concept striver ! I'm just loving your binary search playlist!!!

  • @abhimanyuambastha2595
    @abhimanyuambastha2595 8 месяцев назад +1

    Looked at neetcode video, then yours. His explanation was a bit confusing and had to do some examples to understand it. Yours almost made it a regular easy binary search

  • @sujalgupta6100
    @sujalgupta6100 6 месяцев назад

    Finally understood this problem. Every time I saw rotated sorted array or binary search in general I always skipped.

  • @VasanthChoudary-uc5cz
    @VasanthChoudary-uc5cz 11 месяцев назад +2

    Thankyou for providing this course for free bro.

  • @anddevsahil
    @anddevsahil 7 месяцев назад +1

    Can't find better explanation than striver .

  • @Fe-ironman
    @Fe-ironman 20 дней назад

    what i did was i found the starting point using similar approach of binary search then applied binary search from that point...but this approach is goated

  • @kaushiksen2190
    @kaushiksen2190 Год назад +1

    Amazing video, very good explanations, took sometime to understand but went through it again and again to understand it completely. Thanks for making such quality content Striver Bhai

  • @UserUser-tn8tv
    @UserUser-tn8tv 9 месяцев назад

    Understood Please keep consistent and eventually complete the series of A to Z DSA Course....
    Thank You

  • @PeterParker-ee6ep
    @PeterParker-ee6ep Год назад +1

    everyone just try dry run after you complete video after your understanding, it really in understanding still better. try ittt

  • @adarshmv261
    @adarshmv261 6 месяцев назад

    Understood. The best explanation on youtube for this problem..

  • @seeingsee6593
    @seeingsee6593 Месяц назад

    you are the best teacher I finally understood this problem thank you so much

  • @prernagupta7450
    @prernagupta7450 8 месяцев назад

    YOU Can understand very well and i see a many video but my concept is not clear but just i see that video which would be clearly the concept very easily

  • @ishangujarathi10
    @ishangujarathi10 Год назад +1

    mann unbelievable intuition and explanation!! loved it !!! understood completely

  • @NeerajKar-i7r
    @NeerajKar-i7r Год назад +2

    Great Raj bhai... you deserve to be in elite class.
    keep rocking

  • @mriit3025
    @mriit3025 6 месяцев назад

    best possible understanding through the BS playlist!

  • @fastlaner7746
    @fastlaner7746 2 месяца назад

    "Identify the sorted half" thank you

  • @rrt19254
    @rrt19254 2 месяца назад

    Understood! This man is a legend...

  • @cinime
    @cinime Год назад +2

    Understood! Super fantastic explanation as always, thank you so so much for your effort!!

  • @mirzasohailhussain
    @mirzasohailhussain 3 месяца назад

    Your explanation was much better than neetcodeio, thanks for explaining in such a detail. I was really missing the point to identify sorted part.
    Can you please tell me what app you are using for pencil work.

  • @nagame859
    @nagame859 Год назад

    Understood as always! The intuition/approach is just awesome🤩. Spellbound!

  • @hrishii.02
    @hrishii.02 5 месяцев назад

    Understood! What a simple and affective explaination

  • @jayantmishra2266
    @jayantmishra2266 Год назад +2

    1 QUESTION : will this approach/code work in the case of left rotated array also?? bacause here you explained for right rotated example.

    • @abhaymandal4903
      @abhaymandal4903 Год назад

      Yes , same code will be there for left rotared.

  • @HarshSingh-hk8fe
    @HarshSingh-hk8fe 10 месяцев назад

    bro the way you explain is just amazing thanks a lot

  • @swathigp3818
    @swathigp3818 7 месяцев назад

    This great quality content for free !!! Amazing work , please keep making these great videos 👏👏👏👏

  • @kumpatisupriya3947
    @kumpatisupriya3947 11 месяцев назад

    What an explanation bro..
    You are our lives savior 🙏🙏

  • @somu7441
    @somu7441 Месяц назад

    Only because of you I am loving DSA

  • @revanthkumar5417
    @revanthkumar5417 Год назад

    Best explanation so far in binary search

  • @SameerSuman-ni6fz
    @SameerSuman-ni6fz Месяц назад

    Elimination is key - GOLDEN WORDS

  • @prathamrawat6298
    @prathamrawat6298 4 месяца назад

    bhaiya bhot bhot bhot hi aacha genuinely , bhot pyara samjhaya, too good!

  • @Technocracy07
    @Technocracy07 9 месяцев назад

    When we say that val @low < val @high means array is sorted, how about the case when the array is reverse sorted and rotated somewhere?

  • @qihse1531
    @qihse1531 Год назад +2

    Any thoughts on this corner case not passing: ARR=[3,1], target:1, Why is that? How to generalize the solution?

    • @qihse1531
      @qihse1531 Год назад

      Other than that, beautiful explanation charm💯💯

  • @radha7492
    @radha7492 Год назад +1

    thank you so much sir...respect for your amazing efforts...really no one teaches better than you... raj cum striver..i wish for your long life and happiness..

  • @sreevarshinirg4319
    @sreevarshinirg4319 4 месяца назад

    Understood, Tq for this great help by teaching in youtube for free

  • @secretvibz6300
    @secretvibz6300 4 месяца назад

    Got clearity that what is the main aim of binary search

  • @sanchisingh5117
    @sanchisingh5117 Год назад

    striver's explanations are the best

  • @SupreetSinghsuppi
    @SupreetSinghsuppi 5 месяцев назад

    Great video as always. Can there be a point in the sub array where both the halves are sorted.

  • @mdrejaulhasan5108
    @mdrejaulhasan5108 10 месяцев назад

    you may right is wrong at 14.09 min. As far my understanding high should be high = mid not hing = mid-1 as you are using equal

  • @k.satish3663
    @k.satish3663 Год назад

    Totally understood.your teaching is superb.thank you

  • @Raj-jw7kq
    @Raj-jw7kq 3 месяца назад

    quality GOD LEVEL 🔥 🔥

  • @srutisingh4629
    @srutisingh4629 11 месяцев назад +1

    Hats off to you❤

  • @vinitverma1741
    @vinitverma1741 Год назад +1

    Thank u for such a great explaination

  • @Dibyadipan
    @Dibyadipan 2 месяца назад

    Understood! watching your lectures and taking dsa notes, during college classes 😂❤ (17/8/24)

  • @hareshnayak7302
    @hareshnayak7302 7 месяцев назад

    Understood,Thanks stiver for this amazing video.

  • @yashraj5898
    @yashraj5898 2 дня назад

    great explanation buddy !

  • @umangkumar2005
    @umangkumar2005 9 месяцев назад

    This is the best explanation

  • @satheeshbhukya9970
    @satheeshbhukya9970 Год назад +1

    what"s your key secert key behind this sir i,e that much fluent in DSA 🤗

  • @Akshitrawat121
    @Akshitrawat121 Месяц назад

    9:58 what a expression ;) mtlb mza sa aagya😆

  • @SagarKumar-li4um
    @SagarKumar-li4um Месяц назад +1

    understood sir

  • @saketjaiswalSJ
    @saketjaiswalSJ Год назад

    9:57 sir is so much excited

  • @sandeeprajsaimon8600
    @sandeeprajsaimon8600 4 месяца назад

    best explanation ever

  • @AtulKumar-c4x7l
    @AtulKumar-c4x7l Год назад

    understood
    Thank you striver for making things easy...

  • @rtheame4704
    @rtheame4704 6 месяцев назад

    Very well explained 👏🏻👏🏻

  • @DevanshiKapla
    @DevanshiKapla Год назад +9

    Can anyone share the video link for peak element ?

  • @ashutoshranjan4644
    @ashutoshranjan4644 Год назад

    You have perform binary search in sorted array ( keeping ascending order ) in mind. Am I right? This will not work if array is sorted ( can be in ascending /descending ) order ( not known before hand ). Correct me if I am wrong.

  • @yashraorane578
    @yashraorane578 3 месяца назад

    Best explanation💯

  • @AamilAli2003
    @AamilAli2003 11 дней назад +1

    What about the test cases 2222212 and 212222 😢

  • @harshilpatel3205
    @harshilpatel3205 9 месяцев назад

    Amazing explanation sir 😇!

  • @Abhishekkumarnjw22-vf7cr
    @Abhishekkumarnjw22-vf7cr 3 месяца назад

    Great help you are doing

  • @RajNamdev_19
    @RajNamdev_19 4 месяца назад +1

    Understood :)

  • @rakshitraushan1650
    @rakshitraushan1650 8 месяцев назад

    Understood bro!! Ur a gem!

  • @mathialagant
    @mathialagant 9 месяцев назад

    9:56
    Perfect reaction 😂

  • @tanishkthakur9965
    @tanishkthakur9965 5 месяцев назад +1

    understood

  • @ADITYASRIVASTAVABCE
    @ADITYASRIVASTAVABCE Год назад

    Thankyou for clear explanation. Loved it.

  • @Musicuvakavi1823
    @Musicuvakavi1823 7 месяцев назад

    Understood well thanks for this valuable video sir

  • @rajkumarvb5197
    @rajkumarvb5197 Год назад

    Understood, thanks for your efforts!

  • @Manishgupta200
    @Manishgupta200 Год назад

    other method to solve is first find pivot element and then apply binary search accordingly either on left or on right side based on checking target element with pivot element using assignment operator.

    • @anshulgupta2136
      @anshulgupta2136 Год назад

      worst case wil be O(N) in this.

    • @durnibar3886
      @durnibar3886 Год назад

      no in worst case scenario it wont be O(N), because once you find the pivot, you can either binary search on the left half or the right half, so you need 3 binary searches in total, one for finding the pivot, one for searching on the left half and one for searching on the right half@@anshulgupta2136

  • @ujjawalchourasiya3988
    @ujjawalchourasiya3988 8 месяцев назад

    Love you bhaiya . You are my inspiration ❤

  • @PradeepSingh-ov3bt
    @PradeepSingh-ov3bt 10 месяцев назад

    we can do like this also
    int search(vector& nums, int target) {
    int low,high,mid;
    low = 0;
    high = nums.size()-1;
    while(low

    • @vishious14
      @vishious14 9 месяцев назад

      This looks like a combination of binary search used along with linear search. Theoretically, time complexity of your code is a little higher.

  • @AkhileshChouhan-d4v
    @AkhileshChouhan-d4v 4 месяца назад

    Great explanation.

  • @akaashk623
    @akaashk623 Год назад

    Greatly explained 👏👏

  • @neerajpruthi8350
    @neerajpruthi8350 8 месяцев назад

    Love the explanation. THanks

  • @AshishSharma-kg1yy
    @AshishSharma-kg1yy 4 месяца назад

    woww what a great explanation

  • @mukeshnayal624
    @mukeshnayal624 Год назад

    dill se thank you!

  • @Ginger_Hrn
    @Ginger_Hrn 6 месяцев назад +2

    watching this on 0.75x playback speed feels like I'm watching a drunk person explaining me how to solve this problem.

  • @s3ite
    @s3ite 2 месяца назад

    thanks for the explanation

  • @lshuarckyma
    @lshuarckyma 21 день назад

    understood done and dusted

  • @nikhilkumarjamwal5322
    @nikhilkumarjamwal5322 Год назад

    Nice Explanation!👍

  • @JackSparrow-z8s
    @JackSparrow-z8s Год назад

    Understood striver bhaiya

  • @anishasaini380
    @anishasaini380 7 месяцев назад

    sir Best explanation Thanks!!

  • @Vishal-s2g7c
    @Vishal-s2g7c 3 месяца назад

    understood nicely

  • @apmotivationakashparmar722
    @apmotivationakashparmar722 9 месяцев назад

    Great Explaination

  • @myproject6768
    @myproject6768 Год назад +1

    Absolutely understand ❤