Lecture 24: Search in a Rotated Array | Peak index in a Mountain Array | Kth Missing Positive Number

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

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

  • @CoderArmy9
    @CoderArmy9  Год назад +166

    Hello Coder, Sab chamak rha hai?

  • @focusedstudy7194
    @focusedstudy7194 11 месяцев назад +10

    love you bhaiya chije tough he par laga rahunga aur acche se mehnat karunga aur seekhunga aap se pata ni kyo ek relatability vali feeling aati he thanks for the course
    love you

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

    ye search in rotated array ke question mai bahut din se fasa hua tha. paid course wale ka samaz hi nahi aa raha tha. lekin jab aapke video se dekha to pura logic clear ho gaya.
    thank you for making dsa easy

  • @Nishad_Ranade1729
    @Nishad_Ranade1729 Год назад +8

    Simple brutforce approch:
    for(int i=0;i

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

      leetcode ke 2nd test case prr fail ho jyga

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

      what is n here?

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

      @@collegelife7800 yeh vala try kro, fail nhi hoga,
      class Solution {
      public:
      int findKthPositive(vector& arr, int k)
      {
      int i = 0, num = 0;
      while(k != 0)
      {
      num++;
      if(i < arr.size() && arr[i] == num)
      {
      i++;
      }
      else //arr[i] != num
      {
      k--;
      }
      }
      return num;
      }
      };

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

    Best explanation for search in sorted roated array easiest approach till I seen

  • @jatinteotia0767
    @jatinteotia0767 Год назад +6

    Superb bhaiya the way you are teaching is so unique

  • @joydeep-halder
    @joydeep-halder Год назад +8

    17:52 We can also write the statement in this way.
    mid = end - (end-start)/2; which looks more similar and easy to remember as
    mid = start + (end-start)/2

    • @AbhishekKumar-ks1fd
      @AbhishekKumar-ks1fd Год назад +2

      why mid=start+(end-start)/2 giving error and mid=end+(start-end)/2 not giving error?In both case mid evaluates to zero and also in both cases ig there is no overflow according to condition given in question..

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

      @@AbhishekKumar-ks1fd if we use mid=start+(end-start)/2 then it will move to 0th index if the required element is present at index 1 .and if we use mid=end+(start-end)/2 then it will move to 1st index for which we can compare the previous element arr[mid-1] which is not the case if we use mid=end+(start-end)/2 .for better understanding
      dry run this case [1,9,5,3,2].

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

      @@adeebahmed1891 how will I get to know where to use mid=start+(end-start)/2 and where to use mid=end+(end-start)/2;

    • @_HindiFacts
      @_HindiFacts Год назад +5

      ​@@therealsumitshah it is a better approach. We generally use end+(start-end) /2 . We can use it everywhere.

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

    Literally you are a great teacher , so called overrated teachers can't teach like you brother ! ❤️

  • @ManishKumar-d9b3j
    @ManishKumar-d9b3j 6 месяцев назад +1

    Ram Ram rohit bhai abh kaafi bddiya samajh aa raha hai leetcode ke problems bhi solve kar paa raha hoon all thanx to your great effort to make us fall in love with DSA sab chamk raha hai ✅

  • @Achyutam-j1q
    @Achyutam-j1q День назад

    Hope you are doing well sir . I really appreciate your hard work . Your explaination of each question is so good and it help me to understand the problem as well solution . Thankyou for making this aswome playlist for us.

  • @joydeep-halder
    @joydeep-halder Год назад +15

    My intuition behind ans + K : ✅✅
    We found that in the array before ans index, there are total ans elements present currently.
    And we know there are at least K elements missing
    It means that, before that ans index there should be total at least (ans + k) elements .
    Let's take example of the question:
    [2,3,4,7,11,12] , we found that before index 4th, there are total 4 elements.
    Now, we also know that there are at least 5 elements missing before 4th index.
    so at least total elements before index 4th = 4 elements + at least 5 missing elements = at least 9 elements.
    And we know that 9th element is basically 9 (which is missing)
    (NOTE: In this case total 6 elements missing before index 4, so total elements before 4 would be = 4 + 6 = 10), so 9th element is 9, 10th is 10)

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

    00:01 Find Minimum in Rotated
    18:05 Peak Index
    1:04:55 Kth Missing

  • @rhitam_biswas
    @rhitam_biswas 5 месяцев назад +4

    August 5 : Revision Day 5
    Questions on binary search done ✅✅✅
    (BTW Last question is still little bit tough 😅😅)

  • @Yogesh_Singh_1350
    @Yogesh_Singh_1350 10 месяцев назад +7

    hello bhaiya. Thank you for your efforts.
    {17:25 bhaiya agar hum es code ka use kare tho hume mid value m koi change kare ki jarurat nhai padegi. }
    int s=0,e=arr.size()-1;
    int mid ;
    while(sarr[mid-1]){
    s=mid+1;
    } else{
    e=mid;
    }
    }
    return -1;

    • @Billy-gd1rm
      @Billy-gd1rm 4 месяца назад

      Bhai bhaiya ke rotated array mein dikkat aa rhi hn answer galat aa rhe hn

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

    Bahut tagda lecture tha bhaiya...❤💯🚀

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

    Finally I found the best explanation for search in sorted array

  • @Sajal_Mallick_vlogs
    @Sajal_Mallick_vlogs 10 месяцев назад +1

    Day 32 done and dusted..... Crytal clear everything. Best Bhaiya.... consistency

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

    We are getting motivated by seeing your effort bhaiya..

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

    ajka class thora hardd tha but dry run karta karta samaj aa gya bhaiya thanks ..

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

      Haan Bhai....Kth missing wala smj aaya ?

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

    19:05
    class Solution {
    public:
    int findMin(vector& nums) {
    if(nums[0]

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

    17:44 reason simple hai.
    If you are using comparision for arr-> mid with arr->mid-1.
    use mid = end + (start - end ) /2
    If you are using comparision for arr-> mid with arr->mid+1.
    use mid = start + (end - start) /2
    it depends on your way of writing code.
    ******* Now for the dry run part on : arr [1,6,3,2,1].
    sir Used mid = start + (end - start) /2,
    but used the mid-1 for comparision,
    so for Start = 0, and end = 1.
    mid = 0, now if we try to compare mid with mid -1 , which was accessing the index -1. we got error.

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

      But for example , 2 3 5 4 1 0 , if we write the else if condition as arr[mid] >arr[mid+1] , then end = mid -1 ....then we get error . please check

    • @Educate-Advise-Zone
      @Educate-Advise-Zone 6 месяцев назад

      ​​@@shrutigawade8747it will not reach else ifpart
      it will return mid as peak value i think🤔as first condition will get true..

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

    Really very nice explanation.
    thanks for this type of amazing lectures.

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

    Bhaiya agar code share kar dete to bohot accha hota, thanks for your valuable content, love you

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

    Chamka par yeh vapis dekhna hoga best explanation k liye 👍🏻

  • @naeimsaifi1251
    @naeimsaifi1251 29 дней назад

    bhaiya DSA krne ka mn ni krta tha but apki videos dhk kr mzza aa rha hai or DSA b solve ho rha hai

  • @nitinverma_
    @nitinverma_ 7 месяцев назад +6

    chalu late kiya par maza aara hai bhaiyaaaaaaaaaaa

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

    bhaiya video banana band mat karna bhut se log bhich me hi chod dete he aap please pura course complete kijiyega
    thankyou

  • @yes-its-goliya
    @yes-its-goliya 7 месяцев назад +5

    🏃‍♀Day 9✅
    tysm bhaiya

  • @-BCS-VarshaVaishnav
    @-BCS-VarshaVaishnav Год назад +1

    32/180 done thanku bhaiya🙃

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

    Congratulations for 30k family members Rohit bhaai and CoderArmy family members 🎉

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

    1:35
    class Solution {
    public:
    int peakIndexInMountainArray(vector& arr) {
    int start = 0,end = arr.size()-1,mid;
    while(startarr[mid-1] && arr[mid] > arr[mid+1])
    return mid;
    else if(mid!=arr.size()-1 && arr[mid+1]>arr[mid])
    start = mid+1;
    else
    end = mid-1;
    }
    return start;
    }
    };

  • @deeprajsengar4081
    @deeprajsengar4081 11 месяцев назад +5

    Funny part of video is that kth missing wala code easy category me hai (waah re leetcode) 😂 1:30:24

    • @VivekSingh-hn4xr
      @VivekSingh-hn4xr 10 месяцев назад +1

      😂😂😂😂sahi kha use smjhne mai medium questions se jyada smay lga 😭

    • @deeprajsengar4081
      @deeprajsengar4081 10 месяцев назад +1

      @@VivekSingh-hn4xr real 🥲

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

      ​@@VivekSingh-hn4xrbhai dimag kharab ho gaya

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

    0:0 q1 ,13:26 it's code,18:06 q2 39:35 it's code ,42:45 q3 1:00:34 it's code,1:04:54 q4 1:24:16 it's code and questions description se dekh lena

  • @RiteshKumar-hs3it
    @RiteshKumar-hs3it Год назад +15

    abb mental pressure badh raha h question ki difficulty aur variation k sath kal ki claas ke quesions ko khud se debug krne m 3 ghnte extra lage taki cheeje mentally accept ho jaye 🥲

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

      Same bhai😢

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

      Yeh saare bohot hi simple questions hai, agar yeh bhi tumhe difficult lagg rahe hai toh tumhara basics clear nahi hai, ek baar binary search doobara se padho, different cheeze try karo code me like returning s or e in the end, etc.
      Ek baar binary search samajh gaye toh yeh questions bohot easy lagengi.

    • @rishabhshenoy3258
      @rishabhshenoy3258 7 месяцев назад +2

      ​@@tusharagarwal5306 i agree ye easy hai par ye approach ko aane ke liye practice lagega

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

      @tusharagarwal5306 bro easy hoo ya difficult easy bolke agge niklo ge too mushkil hai question samj ne ki baad bhi ek baar khud se dryrun karo

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

    apne to DSA me aag laga diya , mast he

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

    hi rohit bro this videos is really help full for me thanks for this series

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

    class Solution:
    def findKthPositive(self, arr: List[int], k: int) -> int:
    start = 0
    end = len(arr) - 1
    while end >= start:
    mid = start + (end - start) // 2
    if arr[mid] - 1 - mid < k:
    start = mid + 1
    else:
    end = mid - 1
    return start + k

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

    bhaiyaaa bht zada ache se smjh aa ra hai thank you

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

    bahut bhadiya bhaiya 😀😀😀😀

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

    Your understanding find is very best
    Love you sir ❤❤

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

    Day 24 Completed ✅❤🎉

  • @AmbeDevi-tt1yd
    @AmbeDevi-tt1yd Месяц назад

    At 17:45 if array is 1 2 3 6 1 mid =4+(3-4)/2=4 for(6,1) then for last 1 we have to check for right but this time it should also give us error...so??

  • @Coder-rohits
    @Coder-rohits Год назад +1

    mazaa aa gaya bhaiya iss lecture se ekdam se babu wali feel ho gayi😂😂😂😂

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

    Done Bhaiya... Day 32/180 ✅

  • @GayatriShejule-o1k
    @GayatriShejule-o1k 24 дня назад

    Thank you so much sir🥰

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

    Badhiya rha ye session #Chamka

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

    37:00
    1:03:24 third problem

  • @mydiaryloves
    @mydiaryloves 11 месяцев назад +2

    Thank you bhaiya.

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

    Baap of all dsa teacher rohit negi❤

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

    Day 32/180 completed

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

    sir is like a magician

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

    Done Bhaiya... 32/180 ✅

  • @LordSarcasticVlogger
    @LordSarcasticVlogger 7 месяцев назад +3

    Watching from NIT Srinagar

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

    Please like and share this series with your friends whose not offered paid course ❤

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

    Q peak element
    class Solution {
    public:
    int peakIndexInMountainArray(vector& arr) {
    int n=arr.size();
    int start=0,end=n-1, mid=-1,index=-1;
    while(startarr[mid+1]){
    index=mid;
    end=mid-1;

    }
    else{
    start=mid+1;

    }
    }
    return index;
    }
    };

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

    @Rohit bhai aap hume chamkaane mai mahnat pe lage ho humm market mai chamka denge. 🎉❤ ekdam dhaanshu ja raha h jise bolte hai dhaanshu. Bhai aapne sabb pay after placement bootcamp ke laga di hai achhe se 😂😂😂 aur jitne bhi high price unaffirdable inatituions ke laga di 😂😂😂😅😅😅😅❤❤❤. Rohit bhai coder-army family ki taraf se dil se saalam🙌🙏

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

    Thankyou for 24 😊

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

    doubt
    when to use ;- while(start

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

    Amazing explanation bro ❤❤

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

    Good morning 🌞🌞

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

    every part is amaging====++

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

    Day 32 👍✅ Chamak Gaya

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

    Thank you Bhai ❤

  • @coder-ut6eo
    @coder-ut6eo 8 месяцев назад

    1:04:54 kth missing positive number

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

    search in rotated array confusing bhiyya.but the lecture and efforts of you is good

  • @ManjuBala-vf9ni
    @ManjuBala-vf9ni 5 месяцев назад

    1:00:01 i am confuse in the else if condition ,in the previous example the value of [arr[mid] >= arr[0] ] this condition was not true so how can this code further proceed ?

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

    32/180 Day's full power full power ❤❤❤❤

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

    okay so I've watched this one lecture for like 3-4 hours now and ab jake it has been finished
    now the important thing is ki aaj ke lec ka ek bhi ques khud se nahi hua;
    but still after you giving a simple kickstart dimaag daudne laga bhaiya
    thankyou for the lecture; _/\_

    • @CoderArmy9
      @CoderArmy9  6 месяцев назад +1

      It's comletely fine bhai, focus on making notes and do revision

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

      @@CoderArmy9 already done bhaiya!!

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

      ​@@CoderArmy9almost 9 hours lagge sabhi questions samj aagaye even samja ne ke phele kuch questions samj aagaye par last vala bhot hard tha

  • @AMITKUMAR-ds4hp
    @AMITKUMAR-ds4hp Год назад

    Good morning boss ❤

  • @joydeep-halder
    @joydeep-halder Год назад

    Good morning bhaiya ❤️❤️

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

    Best teacher

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

    ohhh bhaisaaab

  • @GopalKumar-xu3iw
    @GopalKumar-xu3iw Год назад

    Day 32 done ✅✅✅❤❤❤

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

    Good morning 🌞

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

    Thanks for motivating bhai❤

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

    17:52 ka samaj nahi aaya
    Whats the difference between start + (end-start)/2 and end +(start-end)/2 while calculating mid

  • @rohitkr.6408
    @rohitkr.6408 Год назад

    Day-32🔥 Completed
    #180daysofcode
    Covering backlogs

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

    Mast bhaiya.

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

    40:10 and if array assigned discriminate orders then ?

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

    thank you brother

  • @PravilaKumari-uv5be
    @PravilaKumari-uv5be Год назад

    Good morning Bhaiya❤

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

    Good morning negi bhai❤️

  • @Rishi_s.corner
    @Rishi_s.corner 11 месяцев назад

    bhaiya revision done

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

    Bhaiya will you cover dsa from basic to advance on RUclips

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

    Good morning bhaiya..❤️

  • @nikhilPatil-ud2vh
    @nikhilPatil-ud2vh Год назад

    Good morning ❤❤

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

    int peakIndexInMountainArray(vector& arr) {
    int start=0,end=arr.size()-1,mid,ans=-1;
    while(startarr[mid-1] && arr[mid]>arr[mid+1])
    {
    ans = mid;
    break;
    }
    else if(arr[mid+1]>arr[mid])
    {
    start = mid ;
    }
    else{
    end = mid ;
    }
    }
    return ans;
    I have solved this question by my self thanks Bhai ❤

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

    Code samj too agaya par yad hi rakhna padega yiska logic bana bhot mushkil hai

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

    Bhaiya DP k liye bhi series chahiye

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

    Bhaiya ek confusion h agar arrays ko sorted bolte h to it means ki arrays must be in increasing order 🤔🤔.

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

      Nahi bhai, wo question mein given rhega sorted ka meaning, wo increasing ki baat kar rha hai ya decreasing ka

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

    Thanks Bhaiya...❤🎉

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

    32 days completed ✅
    Day 32/180, #180daysofcode #180 hard

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

    okay so i think i know the reason why for Q1 aapke wale mid ne error nai mara
    i think the main reason is that usme 0 ban hi nahi sakta is particular case mein that is 1-1/2=1 as int variable tha
    SERIOUSLY BEAUTIFUL!!!!!!\

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

      Good job my friend ❤️

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

      @@CoderArmy9 bhaiya I'm to still join a college and abhi se I've started this playlist but trust me all of your ways to explaining things have just blown away my mind
      I knew NOTHING about coding whatsoever but from te past 3.5 weeks ive done yaha tak with hw and the process is just FIRE
      WITH ALL DUE RESPECT AND LOVE, THANKS A LOT BHAIYA !!WILL CONTINUE THIS INTENSITY!!

  • @Gauravgaming-g5
    @Gauravgaming-g5 Месяц назад

    bhaiya i got error in kth missing element for arr=[2] and k=1

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

    #32 out of 180

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

    peak index in mountain
    class Solution {
    public:
    int find_pivot(vectorv){
    int s=0, e=v.size()-1;
    int mid = (s+e)/2;
    while(s

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

    this logic of rotated array for finding min. value is not working in {8,7,2,4} why ?

    • @Billy-gd1rm
      @Billy-gd1rm 4 месяца назад

      Pta chala bhai kyo nhi run ho rha please tell

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

    day 32 done!!

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

    Bhaiya last wala kth missing number thoda samajh nhi aaya

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

    Bhaiya dout support ka kya hua!??
    Mene multiple times aa same chiz comment bhi ki different videos pe pr koi reply nhi aata.
    Mene subscription liya hua hai pr jo links aape provide kiya he bo khulte nhi or aap new link provide krbate nhi mene aase a aspect nhi kiya tha!