BS-9. Find Peak Element

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2024
  • Problem Link: bit.ly/3BEDvZC
    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

ความคิดเห็น • 377

  • @takeUforward
    @takeUforward  ปีที่แล้ว +194

    Sorry for the delay :( But I had a product launch, for which I had to spend most of my time in the office. I am back, will try to come with 1/2 videos daily now

    • @charan123rams3
      @charan123rams3 ปีที่แล้ว +8

      Thank you so much sir 🙏
      Sir first take rest whenever you have free time then post sir 🥲

    • @shivanshumishra0560
      @shivanshumishra0560 ปีที่แล้ว +7

      Thankyou so much bhaiya for all videos ...🙏🙏❤️❤️
      Your content is >>>> whole TH-cam

    • @sudhanshushekhar4222
      @sudhanshushekhar4222 ปีที่แล้ว +4

      Understood

  • @sayakghosh5104
    @sayakghosh5104 ปีที่แล้ว +95

    Was trying this for the past 2 days, couldn't solve it. Took 1 day break came back at it again with a fresh mind, could solve it in one go by myself. Thanks, your series instills such confidence in me always.

    • @OrderEmperor
      @OrderEmperor 4 หลายเดือนก่อน +7

      no one asked

    • @sayakghosh5104
      @sayakghosh5104 4 หลายเดือนก่อน +3

      @@OrderEmperor 😂 ok bro.

    • @paraskashyap7362
      @paraskashyap7362 2 หลายเดือนก่อน +9

      @@OrderEmperor no one asked nested(no one asked if no one asked or not)

    • @paraskashyap7362
      @paraskashyap7362 2 หลายเดือนก่อน

      @@arunm619 fair enough

    • @Kj89865
      @Kj89865 หลายเดือนก่อน

      @@paraskashyap7362 calling in return statement (recursion)no one asked if no one asked or not that no one asked :----) *without breaking condition

  • @anujrathore5726
    @anujrathore5726 7 หลายเดือนก่อน +12

    NO ONE CAN TEACH LIKE STRIVER, HE GIVES HIS 100% to his lectures. he want to teach , he compleltly go into the state of teaching , like with full FOCUS & DEDICATION . he enjoy to teach .
    and all of this FREE OF COST , LEGEND AKA RAJ VIKRAMDITYA BHAIYA (STRIVER BHAI OP )

  • @ishanshah3309
    @ishanshah3309 ปีที่แล้ว +16

    the best about this video was the thinking process of how to arrive from linear to binary search in problems like this. execellent stuff.

  • @shivanshugarg807
    @shivanshugarg807 3 หลายเดือนก่อน +9

    Thanks striver I completed all your sheets , like twice , they boost my confidence , before watching your solution , i try every question for 30 mins , and regardless i am able to solve it or not , i watch your video for better understanding and side by side mark improtance of question and make notes for revision

    • @KaifAliKhan-lv4ti
      @KaifAliKhan-lv4ti หลายเดือนก่อน

      ok

    • @3lpme
      @3lpme 28 วันที่ผ่านมา

      Then plz explain why should we consider binary search even though it's not

  • @yashgarg3899
    @yashgarg3899 ปีที่แล้ว +17

    i have solved these questions already so before but still i watch every video of you because i know there will be something different which ultimately enhance my code writing or intuition skills.

  • @ritvikryadav9667
    @ritvikryadav9667 11 หลายเดือนก่อน +6

    Hey Striver, Your videos are pure gem. Certainly the best DSA course on the planet. Keep going. God Bless You!

  • @tanaywhocodes
    @tanaywhocodes 2 วันที่ผ่านมา

    Thank you ! wrote the same code without watching the video. All because of you.

  • @mriit3025
    @mriit3025 4 หลายเดือนก่อน +3

    the extra afforts for the edgecases is appreciated! keep working on content like this...

  • @ankitdhattarwal2286
    @ankitdhattarwal2286 ปีที่แล้ว +7

    There are one mistake in the code when try solve problem on GFG then not pass all the cases the mistake is if(arr[n-1] >= arr[n-2]) return n-1; // use the equal sign also so that can pass all the cases and thank you so much to provide best content

    • @lavanyam3224
      @lavanyam3224 5 หลายเดือนก่อน

      yes, that is because the definition of peak is different in gfg. It says the peak can be greater than or equal to its adjacent elements (a=b) but in leetcode, the peak should be strictly greater (ab)

    • @rakshan3323
      @rakshan3323 หลายเดือนก่อน

      @@lavanyam3224 And that peak definition seems to be correct because here, it doesn't cover the case when all the elements are equal.

  • @iWontFakeIt
    @iWontFakeIt ปีที่แล้ว +8

    was waiting for these past two weeks and you showed up with another awesome explanation! Thanks dada ❤

  • @oguluribrahmaiah1301
    @oguluribrahmaiah1301 8 หลายเดือนก่อน +1

    Commenting Understood is just a simple thing for your wonderful explanation !!!
    Thank you So much for your lectures Striver

  • @GalaxyStart62
    @GalaxyStart62 5 หลายเดือนก่อน +1

    it's a blessing that you are in youtube,
    but on the other side , people are enjoying DSA now, hence , competition is drastically increasing too.

  • @DeepikaKondamadugu
    @DeepikaKondamadugu 3 หลายเดือนก่อน +1

    Didn't even look for completion time of the video!!!.....So that much interesting your videos are❤

  • @mahendrachourasiya7444
    @mahendrachourasiya7444 ปีที่แล้ว +2

    SUPERBBBB Explanation! Thankyou so much for your great efforts.

  • @viveksinghrajput2725
    @viveksinghrajput2725 ปีที่แล้ว +1

    Best explanation on the TH-cam thank you soo much....each and every second of this video is informative.

  • @Dreamer4lyf
    @Dreamer4lyf 3 หลายเดือนก่อน

    Amazing explanation Striver my man! Hats off to you for all your hard work for the community.

  • @RaunitJaiswal-s9v
    @RaunitJaiswal-s9v 2 วันที่ผ่านมา

    done with easy part of binary search from monday will start with medium part
    lots of love raj bhaiya

  • @ishangujarathi10
    @ishangujarathi10 ปีที่แล้ว +4

    GOD LEVEL INTUITION AND EXPLANATION STRIVERRR TYSM < 3!!!

    • @3lpme
      @3lpme 28 วันที่ผ่านมา

      Kaise develop hogi iss intuition from inside?😢

  • @pizzagamingyt9712
    @pizzagamingyt9712 ปีที่แล้ว +2

    Bro u are the most helpful person for all engineering cse student 🧡❤

  • @AdityaGarg-hl7ri
    @AdityaGarg-hl7ri 8 หลายเดือนก่อน

    Thankyou striver, still maintaining that low=m+1 and high =m-1 thing which makes it super easy to understand!!

  • @madhulikaghosh3876
    @madhulikaghosh3876 5 หลายเดือนก่อน

    Your explanation is crazy. You are really doing a very good job.

  • @theengineer8301
    @theengineer8301 4 หลายเดือนก่อน

    Hi Striver, this was an epic explanation. Hats off!
    However I think we can only check the left element of mid. If greater then eliminate right. Else eliminate left. No need for the other if condition.
    class Solution {
    public:
    int findPeakElement(vector& arr) {
    int n = arr.size();
    if(n == 1) return 0;
    if(arr[0] > arr[1]) return 0;
    if(arr[n-1] > arr[n-2]) return n-1;
    int low = 1;
    int high = n - 2;
    int mid;
    while(low arr[mid+1] )
    return mid;
    //mid-1 greater than mid, peak on left,eliminate right
    if(arr[mid-1] > arr[mid])
    high = mid - 1;
    //peak on right, eliminate left
    else
    low = mid + 1;
    }
    return mid;
    }
    };

    • @expanse8846
      @expanse8846 หลายเดือนก่อน

      he explained it by the end. it may lead to an infinite loop if there are multiple peaks.

  • @RaunitJaiswal-s9v
    @RaunitJaiswal-s9v 2 วันที่ผ่านมา

    for those who are facing problem with the if else part for the right side here is the easy way to think If the element to the right of mid is greater (arr[mid] < arr[mid + 1]), we move to the right half (since there must be a peak in that direction).

  • @girivardhanvelpula
    @girivardhanvelpula 7 หลายเดือนก่อน +2

    00:04 Find the peak element in an array
    02:16 Identifying peak elements using the concept of infinity assumptions.
    06:42 Peak element finding in a sorted array using binary search
    09:03 Binary search to find peak element
    13:59 Identifying peak in decreasing curve
    16:22 Dealing with the cases of the first and last elements as peak elements.
    20:38 Finding peak element in an array using binary search
    22:54 In a decreasing curve, the mid element is greater than the right element.
    27:08 Binary search can efficiently find the peak element
    29:08 Algorithm to find peak element in an array

    • @3lpme
      @3lpme 28 วันที่ผ่านมา

      first of all it's not sorted array 06:42

  • @ParkersFact_Finder
    @ParkersFact_Finder 11 วันที่ผ่านมา

    how you think like that striver i mean your thought process is totally diff how can i achieve this type of thought process honestly Best DSA playlist

  • @Dipanshutripathi2407
    @Dipanshutripathi2407 11 หลายเดือนก่อน +1

    Filled with full confidence after watching ur videos.

  • @graviton001
    @graviton001 หลายเดือนก่อน

    Was able to do it myself 😮 thnx for building up my logical thinking ❤

  • @abhijittalukdar6995
    @abhijittalukdar6995 ปีที่แล้ว

    Bhaiya I solved this without seeing the video. Because i have learnt the concepts from your earlier videos. Thanks and LOTS of LOVE.

  • @Manishgupta200
    @Manishgupta200 ปีที่แล้ว

    THe last one infinite loop example was very helpful to understand the problems condition clearly.

  • @Harsh-x5o9f
    @Harsh-x5o9f 2 หลายเดือนก่อน

    The man who is making every CSE student's career bright

  • @Raj10185
    @Raj10185 ปีที่แล้ว

    Tysm first time i got clear cut intution of finding the peak element :) tysm again UNDERSTOOD EVERYTHING:)

  • @cinime
    @cinime ปีที่แล้ว +2

    Understood! Super awesome explanation as always, thank you very much for your effort, and congrats for your product launch!! Is this idea used to find the derivative local maximum / minimum?

  • @deepanshudahiya8966
    @deepanshudahiya8966 3 หลายเดือนก่อน

    An amazing question learning new patterns of conditions in binary search

  • @Josuke217
    @Josuke217 หลายเดือนก่อน

    This was pretty easy, finally solved it on my own.

  • @ashishrajoria2251
    @ashishrajoria2251 7 วันที่ผ่านมา

    public int findPeakElement(int[] nums) {
    int left = 0, right = nums.length - 1;
    while (left < right) {
    int mid = left + (right - left) / 2;
    if (nums[mid] > nums[mid + 1]) {
    right = mid;
    } else {
    left = mid + 1;
    }
    }
    return left;
    }

  • @hashcodez757
    @hashcodez757 8 หลายเดือนก่อน

    Understood very well sir!!
    No words for your appeciation bhaiya

  • @Raj10185
    @Raj10185 ปีที่แล้ว +2

    code for the same :-
    int findPeakElement(vector& arr) {

    int n = arr.size();

    //checking done for initial cases where finding and is very easy

    if(n==1) //edgecase1
    return 0;

    if(arr[0] > arr[1]) //edgecase 2
    return 0;

    if(arr[n-1] > arr[n-2]) //edgecase 3
    return n-1;



    // now apply bS on remaining part

    int l = 1;
    int r = n-2;






    while(larr[mid+1] && arr[mid]>arr[mid-1])
    {
    return mid ;
    }

    else if (arr[mid]>arr[mid-1]) //mid on the increasing path that means our ans will be in right side
    l = mid+1;
    else // mid is on the decreasing path peak will be on left side
    r = mid -1;

    }






    return -1;




    }

    • @AppaniMadhavi
      @AppaniMadhavi 7 หลายเดือนก่อน

      not working for all testcases in coding ninjas

  • @saambpatil9912
    @saambpatil9912 ปีที่แล้ว +4

    iNSTEAD OF ADDING THE LAST CONDITION WE CAN CHANGE THE ABOE CONDITIONS TO :
    else if (nums[mid] < nums[mid + 1])
    {
    low = mid + 1;
    }
    else if (nums[mid] < nums[mid - 1])
    {
    high = mid - 1;
    }
    COMPLETE CODE:
    class Solution
    {
    public:
    int findPeakElement(vector &nums)
    {
    int n = nums.size();
    if (n == 1)
    {
    return 0;
    }
    if (nums[0] > nums[1])
    {
    return 0;
    }
    if (nums[n - 1] > nums[n - 2])
    {
    return n - 1;
    }
    int low = 1;
    int high = n - 2;
    while (high >= low)
    {
    int mid = low + (high - low) / 2;
    if (nums[mid] > nums[mid + 1] && nums[mid] > nums[mid - 1])
    {
    return mid;
    }
    else if (nums[mid] < nums[mid + 1])
    {
    low = mid + 1;
    }
    else if (nums[mid] < nums[mid - 1])
    {
    high = mid - 1;
    }
    }
    return 0;
    }
    };

  • @socify4410
    @socify4410 9 หลายเดือนก่อน

    solved by my own thanks a lot Striver Bro keep spreading the knowledge

  • @noone1000_xyz
    @noone1000_xyz 9 หลายเดือนก่อน

    at the end of video i am just surprised.......understood very clearly.....thankssss a lottttt striver......

  • @gokulkrishnanj
    @gokulkrishnanj 2 หลายเดือนก่อน

    Nice explanation on that hidden test case

  • @shailesh_rajpurohit
    @shailesh_rajpurohit ปีที่แล้ว +2

    3:20 here 3 is also peak

  • @AtulKumar-c4x7l
    @AtulKumar-c4x7l ปีที่แล้ว

    understood
    Thank you striver for such an amazing explanation...

  • @harshitsingh3510
    @harshitsingh3510 5 หลายเดือนก่อน +5

    can we simply find the largest and return that index , it will also give the peak😜

    • @mohitt_amv
      @mohitt_amv หลายเดือนก่อน +1

      it will take o(n) if im not wrong!?

  • @kenkaneki669
    @kenkaneki669 ปีที่แล้ว +2

    Damn, was eagerly waiting for this!!!

  • @user-eq9zo5vj7c
    @user-eq9zo5vj7c 10 วันที่ผ่านมา

    Someone wrote and I quote "Striver can transfer his confidence to his students" .

  • @piyushwandile4152
    @piyushwandile4152 ปีที่แล้ว

    great content no one teach like this atleast for free

  • @codewithabhi1089
    @codewithabhi1089 3 หลายเดือนก่อน

    Hii Striver , I think if it chooses else part then it will go towards either left part or right one but in the end we will end up having one element as the peak one. Don't understand on that part. Can you please explain this??

  • @rohitkumarpilania94
    @rohitkumarpilania94 ปีที่แล้ว

    welcome back, waited for you every single day

  • @NewtonVarma
    @NewtonVarma 2 หลายเดือนก่อน

    If we are to return an array of indices where peaks are found(all peak) can we still apply binary search by making some modifications and applying if else checkups. 🤔

  • @PiyushKumar-xe1ng
    @PiyushKumar-xe1ng 2 หลายเดือนก่อน

    int start = 0;
    int end = n - 1;
    while (start < end) {
    int mid = start + (end - start) / 2;
    if (arr[mid] < arr[mid + 1]) {
    start = mid + 1;
    }
    else {
    end = mid;
    }
    }
    return start; (how about this ,easy and covers every edge case)

  • @Codro09
    @Codro09 5 หลายเดือนก่อน

    This is the brute linear solution :
    class Solution {
    public:
    int findPeakElement(vector& nums) {
    //Brute force:
    int n = nums.size();
    int ans = INT_MIN;
    int peak_index = -1;
    if(n==1) return 0;
    for(int i = 0; i < n; i++){
    if (nums[i] > ans) {
    ans = nums[i];
    peak_index = i;
    }
    }
    return peak_index;
    }
    };

  • @padmaja577
    @padmaja577 5 หลายเดือนก่อน

    Firstly the brute force psudeo code will only for:
    1) array which has one peak element.
    2) array is in ascending order
    3) array is in descending order.

  • @TrinmoyDutta
    @TrinmoyDutta 6 หลายเดือนก่อน

    while(low < high-1){
    mid = (low+high)/2;
    if(arr[mid]>arr[mid+1] && arr[mid]>arr[mid-1]) return arr[mid];
    if(arr[mid+1]>arr[mid]) low = mid+1;
    else high = mid-1;
    }
    if(arr[low]>arr[high]) return arr[low];
    else return arr[high];
    initially came up with this solution, it was working and was accepted in leetcode

  • @saswatrath4646
    @saswatrath4646 5 หลายเดือนก่อน

    at 21:15 correction* if(arr[o] > arr[1]) return 0; the first index is the peak

  • @ShivamYadav-in2jg
    @ShivamYadav-in2jg ปีที่แล้ว +2

    Hey Striver , the above method did not worked for this array : {1,1,51,2,3,4,5,6,7,7} , it gave "No Peak".

    • @riteshkumargupta4386
      @riteshkumargupta4386 ปีที่แล้ว +3

      you cannot have same value at 2 consecutive indexs, therefore this is not a valid input

    • @naga_stark
      @naga_stark 7 หลายเดือนก่อน

      if(arr[mid]>=arr[mid+1] && arr[mid]>=arr[mid-1]) return mid; // just add a equal operator to handle plateau case

    • @pradeepvarma_22
      @pradeepvarma_22 หลายเดือนก่อน

      nums[i] != nums[i + 1] for all valid i as mentioned in problem. but (1,51,2,3,4,5,6,7) 51,7 is peak so it will ignore 51 and pick 7 as peak

  • @hareshnayak7302
    @hareshnayak7302 5 หลายเดือนก่อน

    Understood,thanks striver for this amazing video.

  • @muntasirayan6006
    @muntasirayan6006 7 หลายเดือนก่อน

    if we give last condition (else high = mid -1;) that will work for both 1 peak element and also multi peak element.

  • @charan123rams3
    @charan123rams3 ปีที่แล้ว +3

    Sir please complete as soon as possible please sir 🙏🙏😢

  • @Harshitha45-sde
    @Harshitha45-sde หลายเดือนก่อน +1

    Bs-9 Done ✅
    Weekend 27 July 2024
    7:43 pm

  • @anshpalekar152
    @anshpalekar152 2 หลายเดือนก่อน

    But what if question is [1,2,1,3,5,6,4] , it will eliminate left half and go to right where peak is not there

  • @manavsingh5919
    @manavsingh5919 ปีที่แล้ว

    Thank You Striver..Understood everything🙂

  • @Ald0Abdiel
    @Ald0Abdiel 5 หลายเดือนก่อน

    Amazing explanation! thanks teacher :)

  • @VarshaSingh-hi2sb
    @VarshaSingh-hi2sb หลายเดือนก่อน

    So someone please clear my doubt binary search is for sorted elements and here the elements might or might not be sorted so will the results be right in all cases if true then why we say BS is applied on sorted elements?

  • @arunm619
    @arunm619 2 หลายเดือนก่อน

    Reversal of a peak is called trough. 30:29

  • @casafurix
    @casafurix 11 หลายเดือนก่อน

    wow, the reversal peak, beautiful

  • @Mousam_Sharma
    @Mousam_Sharma 9 หลายเดือนก่อน

    Understood .best Explanation 👍

  • @dank7044
    @dank7044 10 หลายเดือนก่อน

    absolute beauty of a question

  • @kayathrivenkatesan7712
    @kayathrivenkatesan7712 ปีที่แล้ว

    Great video sir..thank u for saving us

  • @rashikhandelwal4121
    @rashikhandelwal4121 3 หลายเดือนก่อน

    Bestest explanation ❤

  • @umangkumar2005
    @umangkumar2005 7 หลายเดือนก่อน

    while going through your tutorial i am just taking hint for some question how to eliminate left or right array rest of the code i am doing myself?
    int findPeakElement(vector &arr) {
    int n= arr.size();
    if(n==1){
    return 0;
    }
    if(arr[0]>arr[1]){
    return 0;
    }
    if(arr[n-1]>arr[n-2]){
    return n-1;
    }

    int low =1;
    int high=n-1;
    int mid= low+(high-low)/2;
    while(lowarr[mid-1]&& arr[mid]>arr[mid+1]){
    return mid;
    }
    else if(arr[mid]>arr[mid-1] && arr[mid]

  • @agamsrivastava8037
    @agamsrivastava8037 9 หลายเดือนก่อน

    In the last example peak element will be 3 instead of 5 @3:34

  • @HARSHITHAD-r9z
    @HARSHITHAD-r9z 5 หลายเดือนก่อน

    How can we print all peak elements? Example - [1, 2, 1, 3, 5, 6, 4] where 2 and 6 are peaks and it only prints 6.

    • @saswatrath4646
      @saswatrath4646 5 หลายเดือนก่อน

      Our bs solution is forged in a way that we move towards one og the peak, to return multiple peak or all peaks, there isn't a solution having O(log n) complexity, for that you can take help of linear search.

  • @SumitSingh-dc8pm
    @SumitSingh-dc8pm 9 หลายเดือนก่อน

    How about if we have duplicates, then simply do that low++ and high-- ?

  • @LokeshKumar-lv3zq
    @LokeshKumar-lv3zq 2 หลายเดือนก่อน

    Compiling your Code...
    > Success!
    Running Test Cases...
    > TestCase - Easy Failed
    Wrong Answer
    Your program's output doesn't match the expected output. You can try testing your code with custom input and try putting debug statements in your code.
    Your submission failed for the following input
    Arg 1: An Integer Array, For e.g [1,2,3]
    [1,1000000000,1000000000]
    Test As Custom Input
    The expected return value:
    1000000000
    Your function returned the following:
    -1
    Final Verdict
    > Wrong Answer
    Failing for input - [1,1000000000,1000000000] can someone help me Identify the error(Note: the code is same as mentioned in this video)

  • @user-to6mg5mz7n
    @user-to6mg5mz7n 3 หลายเดือนก่อน

    Excellent explanation

  • @boomerofficial7177
    @boomerofficial7177 8 หลายเดือนก่อน

    Kya question samjhaya hai bhai 👍👍👍

  • @ammanchhetri6716
    @ammanchhetri6716 ปีที่แล้ว

    there is also a brute force approach using stl ....that is we know whatever the case is.... the maximum element of the vector is always a peak element...so we just return the index of the max element....
    int ind = max_element( nums.begin(), nums.end() ) - nums.begin() ;
    ig

  • @rohitsai806
    @rohitsai806 ปีที่แล้ว

    Fantastic teaching...!

  • @siddunihary
    @siddunihary 3 หลายเดือนก่อน

    Strivers Sir You Are The Best

  • @dipingrover1970
    @dipingrover1970 3 หลายเดือนก่อน

    very good explanation .

  • @riteshbisht94
    @riteshbisht94 8 หลายเดือนก่อน +1

    God level content 🥵 🔥🔥

  • @andrewbeef8758
    @andrewbeef8758 ปีที่แล้ว

    DSA me bhaiyaa aap BAAP ho , ye sayad appko khud nahi pata , Love u bhaiya

  • @yagnasriparsi9500
    @yagnasriparsi9500 6 หลายเดือนก่อน

    Hey To use Binary Search Array should be sorted right but we are not sorting the array

  • @kingbadshah452
    @kingbadshah452 7 หลายเดือนก่อน

    thanks striver understood everything

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 ปีที่แล้ว

    Very well explained. Understood

  • @Nainalarenukadevi9196-dh8rz
    @Nainalarenukadevi9196-dh8rz 4 หลายเดือนก่อน

    after elimination one half how can you say the peak will be present at other half, there is a chance that that peak also present at eliminated half.. anyone can explain..

  • @jayeshtotlani
    @jayeshtotlani 3 หลายเดือนก่อน

    what happens when mid mid+1 and mid-1 element are same and hence peak can be on any side ? is that test case not included on leetcode where there is only one peak and mid mid+1 and mid-1 are same

    • @cat_therepy
      @cat_therepy หลายเดือนก่อน

      this will not considered any test case for the peak element

  • @snehil7855
    @snehil7855 8 หลายเดือนก่อน

    If the array contains a continuous peak ,i.e, same values repeating as peak like (1,2,2,1) we can use the condition of (arr[mid]>=arr[mid-1] && arr[mid]>=arr[mid+1]) this will handle a case like this

    • @saswatrath4646
      @saswatrath4646 5 หลายเดือนก่อน

      will save us one iteration maybe... yes haha

  • @snehashisratna9074
    @snehashisratna9074 10 หลายเดือนก่อน

    luv the way u teach

  • @ashokyadavfqplmgxjia4668
    @ashokyadavfqplmgxjia4668 10 หลายเดือนก่อน

    far better than other vedio

  • @maccode07
    @maccode07 21 ชั่วโมงที่ผ่านมา

    THANK U STRIVER

  • @hariomtiwari7605
    @hariomtiwari7605 10 หลายเดือนก่อน +1

    UNDERSTOOD 👌👌👌👌👏👏👏👏

  • @sukritinarang5016
    @sukritinarang5016 7 หลายเดือนก่อน

    Great Playlist . 👍

  • @ManavMSanger
    @ManavMSanger 10 หลายเดือนก่อน

    What if we have to find the maximum peak element out of all peak elements? Can we still do it in O(log n) ?

  • @RajNamdev_19
    @RajNamdev_19 2 หลายเดือนก่อน +1

    Understood.

  • @ganeshjaggineni4097
    @ganeshjaggineni4097 3 หลายเดือนก่อน

    NICE SUPER EXCELLENT MOTIVATED

  • @RahulBisht_001
    @RahulBisht_001 10 หลายเดือนก่อน

    But what if we need to find all the peak elements. then linear search is the only option I think 🤔🤔🤔🤔🤔🤔or their any better algo

  • @adityasood04
    @adityasood04 ปีที่แล้ว +2

    sir, what will be peak element if all elements in array will be same eg {3,3,3}

    • @takeUforward
      @takeUforward  ปีที่แล้ว

      invalid input h na, question pdho

    • @adityasood04
      @adityasood04 ปีที่แล้ว +1

      @@takeUforward sir, actually gfg me ek test case hai esa {2,2}

    • @shramanjain08
      @shramanjain08 ปีที่แล้ว +1

      @@adityasood04 just do a small change in the condition for finding peak use equal in both equation
      If arr[mid]>=arr[mid-1] and arr[mid]>=arr[mid+1]:
      return mid

    • @deeptidip9864
      @deeptidip9864 ปีที่แล้ว

      ​@@shramanjain08still error!!

    • @adityasood04
      @adityasood04 ปีที่แล้ว

      @@shramanjain08 thanks bro🥂