BS-9. Find Peak Element

  Рет қаралды 151,593

take U forward

take U forward

Жыл бұрын

Problem Link: bit.ly/3BEDvZC
Notes/C++/Java/Python codes: takeuforward.org/data-structu...
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/takeUforward
0:00 Introduction of Course

Пікірлер: 342
@takeUforward
@takeUforward Жыл бұрын
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 Жыл бұрын
Thank you so much sir 🙏 Sir first take rest whenever you have free time then post sir 🥲
@shivanshumishra0560
@shivanshumishra0560 Жыл бұрын
Thankyou so much bhaiya for all videos ...🙏🙏❤️❤️ Your content is >>>> whole KZbin
@sudhanshushekhar4222
@sudhanshushekhar4222 Жыл бұрын
Understood
@sayakghosh5104
@sayakghosh5104 Жыл бұрын
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 3 ай бұрын
no one asked
@sayakghosh5104
@sayakghosh5104 3 ай бұрын
@@OrderEmperor 😂 ok bro.
@paraskashyap7362
@paraskashyap7362 Ай бұрын
@@OrderEmperor no one asked nested(no one asked if no one asked or not)
@paraskashyap7362
@paraskashyap7362 Ай бұрын
@@arunm619 fair enough
@Kj89865
@Kj89865 7 күн бұрын
@@paraskashyap7362 calling in return statement (recursion)no one asked if no one asked or not that no one asked :----) *without breaking condition
@shivanshugarg807
@shivanshugarg807 Ай бұрын
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
@anujrathore5726
@anujrathore5726 5 ай бұрын
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 Жыл бұрын
the best about this video was the thinking process of how to arrive from linear to binary search in problems like this. execellent stuff.
@ritvikryadav9667
@ritvikryadav9667 10 ай бұрын
Hey Striver, Your videos are pure gem. Certainly the best DSA course on the planet. Keep going. God Bless You!
@yashgarg3899
@yashgarg3899 Жыл бұрын
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.
@iWontFakeIt
@iWontFakeIt Жыл бұрын
was waiting for these past two weeks and you showed up with another awesome explanation! Thanks dada ❤
@mriit3025
@mriit3025 3 ай бұрын
the extra afforts for the edgecases is appreciated! keep working on content like this...
@viveksinghrajput2725
@viveksinghrajput2725 Жыл бұрын
Best explanation on the KZbin thank you soo much....each and every second of this video is informative.
@oguluribrahmaiah1301
@oguluribrahmaiah1301 7 ай бұрын
Commenting Understood is just a simple thing for your wonderful explanation !!! Thank you So much for your lectures Striver
@mahendrachourasiya7444
@mahendrachourasiya7444 11 ай бұрын
SUPERBBBB Explanation! Thankyou so much for your great efforts.
@Dreamer4lyf
@Dreamer4lyf Ай бұрын
Amazing explanation Striver my man! Hats off to you for all your hard work for the community.
@ishangujarathi10
@ishangujarathi10 Жыл бұрын
GOD LEVEL INTUITION AND EXPLANATION STRIVERRR TYSM < 3!!!
@pizzagamingyt9712
@pizzagamingyt9712 Жыл бұрын
Bro u are the most helpful person for all engineering cse student 🧡❤
@GalaxyStart62
@GalaxyStart62 4 ай бұрын
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.
@AdityaGarg-hl7ri
@AdityaGarg-hl7ri 7 ай бұрын
Thankyou striver, still maintaining that low=m+1 and high =m-1 thing which makes it super easy to understand!!
@madhulikaghosh3876
@madhulikaghosh3876 3 ай бұрын
Your explanation is crazy. You are really doing a very good job.
@Dipanshutripathi2407
@Dipanshutripathi2407 10 ай бұрын
Filled with full confidence after watching ur videos.
@rohitkumarpilania94
@rohitkumarpilania94 Жыл бұрын
welcome back, waited for you every single day
@Raj10185
@Raj10185 Жыл бұрын
Tysm first time i got clear cut intution of finding the peak element :) tysm again UNDERSTOOD EVERYTHING:)
@socify4410
@socify4410 7 ай бұрын
solved by my own thanks a lot Striver Bro keep spreading the knowledge
@cinime
@cinime Жыл бұрын
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?
@Manishgupta200
@Manishgupta200 Жыл бұрын
THe last one infinite loop example was very helpful to understand the problems condition clearly.
@ankitdhattarwal2286
@ankitdhattarwal2286 Жыл бұрын
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 4 ай бұрын
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 21 сағат бұрын
@@lavanyam3224 And that peak definition seems to be correct because here, it doesn't cover the case when all the elements are equal.
@hashcodez757
@hashcodez757 6 ай бұрын
Understood very well sir!! No words for your appeciation bhaiya
@DeepikaKondamadugu
@DeepikaKondamadugu 2 ай бұрын
Didn't even look for completion time of the video!!!.....So that much interesting your videos are❤
@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.
@user-ti3bd8mp1w
@user-ti3bd8mp1w Жыл бұрын
understood Thank you striver for such an amazing explanation...
@graviton001
@graviton001 7 күн бұрын
Was able to do it myself 😮 thnx for building up my logical thinking ❤
@kenkaneki669
@kenkaneki669 Жыл бұрын
Damn, was eagerly waiting for this!!!
@hareshnayak7302
@hareshnayak7302 4 ай бұрын
Understood,thanks striver for this amazing video.
@dank7044
@dank7044 9 ай бұрын
absolute beauty of a question
@deepanshudahiya8966
@deepanshudahiya8966 2 ай бұрын
An amazing question learning new patterns of conditions in binary search
@rohitsai806
@rohitsai806 10 ай бұрын
Fantastic teaching...!
@Mousam_Sharma
@Mousam_Sharma 7 ай бұрын
Understood .best Explanation 👍
@manavsingh5919
@manavsingh5919 11 ай бұрын
Thank You Striver..Understood everything🙂
@kayathrivenkatesan7712
@kayathrivenkatesan7712 Жыл бұрын
Great video sir..thank u for saving us
@girivardhanvelpula
@girivardhanvelpula 5 ай бұрын
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
@Ald0Abdiel
@Ald0Abdiel 4 ай бұрын
Amazing explanation! thanks teacher :)
@Josuke217
@Josuke217 14 күн бұрын
This was pretty easy, finally solved it on my own.
@noone1000_xyz
@noone1000_xyz 8 ай бұрын
at the end of video i am just surprised.......understood very clearly.....thankssss a lottttt striver......
@piyushwandile4152
@piyushwandile4152 11 ай бұрын
great content no one teach like this atleast for free
@AnmolGupta-oj4lm
@AnmolGupta-oj4lm Жыл бұрын
Understood Very Well!
@dayashankarlakhotia4943
@dayashankarlakhotia4943 Жыл бұрын
Very well explained. Understood
@rashikhandelwal4121
@rashikhandelwal4121 Ай бұрын
Bestest explanation ❤
@snehashisratna9074
@snehashisratna9074 9 ай бұрын
luv the way u teach
@sukritinarang5016
@sukritinarang5016 6 ай бұрын
Great Playlist . 👍
@Aman_Panchal27
@Aman_Panchal27 9 ай бұрын
understood, you are BEST !
@mehrabhossain8225
@mehrabhossain8225 7 ай бұрын
you are really great one ..
@akashddeepchitransh4537
@akashddeepchitransh4537 9 ай бұрын
Mind blowing video..
@user-gl4fs5hn3m
@user-gl4fs5hn3m Ай бұрын
The man who is making every CSE student's career bright
@ariesgaming4580
@ariesgaming4580 11 ай бұрын
Understood perfectly!!!!
@gokulkrishnanj
@gokulkrishnanj 22 күн бұрын
Nice explanation on that hidden test case
@user-to6mg5mz7n
@user-to6mg5mz7n 2 ай бұрын
Excellent explanation
@samuelfrank1369
@samuelfrank1369 10 ай бұрын
Understood . Thanks a lot.
@kingbadshah452
@kingbadshah452 5 ай бұрын
thanks striver understood everything
@dipingrover1970
@dipingrover1970 Ай бұрын
very good explanation .
@ashokyadavfqplmgxjia4668
@ashokyadavfqplmgxjia4668 9 ай бұрын
far better than other vedio
@NazeerBashaShaik
@NazeerBashaShaik 3 ай бұрын
Understood, thank you.
@jagannathan1014
@jagannathan1014 8 ай бұрын
Dude you're a god🙏
@theengineer8301
@theengineer8301 3 ай бұрын
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 11 күн бұрын
he explained it by the end. it may lead to an infinite loop if there are multiple peaks.
@casafurix
@casafurix 10 ай бұрын
wow, the reversal peak, beautiful
@boomerofficial7177
@boomerofficial7177 6 ай бұрын
Kya question samjhaya hai bhai 👍👍👍
@Shunya_Advait
@Shunya_Advait 11 ай бұрын
Understood Sir.👌
@harshilpatel3205
@harshilpatel3205 6 ай бұрын
Thank you striver 😇🙌
@saambpatil9912
@saambpatil9912 Жыл бұрын
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; } };
@user-pz4uy2qu7r
@user-pz4uy2qu7r 8 ай бұрын
Well understood.
@sallu_-bhai
@sallu_-bhai 6 ай бұрын
Love ur apoorach sir 😁
@hariomtiwari7605
@hariomtiwari7605 9 ай бұрын
UNDERSTOOD 👌👌👌👌👏👏👏👏
@siddunihary
@siddunihary 2 ай бұрын
Strivers Sir You Are The Best
@ganeshjaggineni4097
@ganeshjaggineni4097 2 ай бұрын
NICE SUPER EXCELLENT MOTIVATED
@CodeMode9313
@CodeMode9313 11 ай бұрын
shukriya habibi ..
@saravanajothigandhirajan6570
@saravanajothigandhirajan6570 21 күн бұрын
Loved it
@parassetia4964
@parassetia4964 Ай бұрын
Understood boss!!
@harshit.53
@harshit.53 4 ай бұрын
bro u are great...
@sajjanshah4508
@sajjanshah4508 11 ай бұрын
Understoood👍
@md.imrankhan6912
@md.imrankhan6912 11 ай бұрын
Legendary Boss
@utsavseth6573
@utsavseth6573 Жыл бұрын
Lovely striver.
@harshitsingh3510
@harshitsingh3510 4 ай бұрын
can we simply find the largest and return that index , it will also give the peak😜
@jitesh_khurana
@jitesh_khurana Жыл бұрын
UNDERSTOOD SIR
@senseiAree
@senseiAree 10 ай бұрын
Understood ❤
@user-or5oz1pk2x
@user-or5oz1pk2x 3 ай бұрын
Thanks a lot Bhaiya
@abhay9994
@abhay9994 9 ай бұрын
Thank you.
@pavansai2859
@pavansai2859 4 ай бұрын
God level ❤‍🔥
@abhishekpardeshi8506
@abhishekpardeshi8506 Жыл бұрын
Understood 😊
@culeforever5408
@culeforever5408 9 ай бұрын
understood 😇
@user-is6ky7pp2n
@user-is6ky7pp2n 2 ай бұрын
Understood !! 😎😎
@ChethanV-w8l
@ChethanV-w8l 17 күн бұрын
Thank you
@Balaji-vx6uj
@Balaji-vx6uj 3 ай бұрын
Understood👍
@jayeshtotlani
@jayeshtotlani 2 ай бұрын
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
@swetaacharya2969
@swetaacharya2969 Жыл бұрын
Thank you bhaiya ❤
@NewtonVarma
@NewtonVarma Ай бұрын
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. 🤔
@yagnasriparsi9500
@yagnasriparsi9500 5 ай бұрын
Hey To use Binary Search Array should be sorted right but we are not sorting the array
@Shivi32590
@Shivi32590 Ай бұрын
thank you
@Sanjaysview
@Sanjaysview 6 ай бұрын
good one
@Raj10185
@Raj10185 Жыл бұрын
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 5 ай бұрын
not working for all testcases in coding ninjas
@dipakgupta2533
@dipakgupta2533 4 ай бұрын
Understood!! :)
@ymishra7790
@ymishra7790 11 ай бұрын
Understood! 😁
@riteshbisht94
@riteshbisht94 6 ай бұрын
God level content 🥵 🔥🔥
BS-10. Finding Sqrt of a number using Binary Search
17:11
take U forward
Рет қаралды 110 М.
Find Peak Element - Leetcode 162 - Python
11:02
NeetCodeIO
Рет қаралды 36 М.
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 11 МЛН
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 36 МЛН
EVOLUTION OF ICE CREAM 😱 #shorts
00:11
Savage Vlogs
Рет қаралды 11 МЛН
ПРОВЕРИЛ АРБУЗЫ #shorts
00:34
Паша Осадчий
Рет қаралды 7 МЛН
BS-8. Single Element in Sorted Array
22:16
take U forward
Рет қаралды 134 М.
What is asked in every Machine Learning interview?
11:43
MLEpath
Рет қаралды 1,8 М.
Binary Search Algorithm - Computerphile
18:34
Computerphile
Рет қаралды 158 М.
Re-rating GD levels!
4:12
DayStudio
Рет қаралды 7 М.
FINISHING My FIRST 2.2 Level!
13:38
Sdslayer
Рет қаралды 19 М.
L22. Rotate a LinkedList
12:10
take U forward
Рет қаралды 51 М.
BS-12. Koko Eating Bananas
21:04
take U forward
Рет қаралды 142 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 633 М.
BS-24. Search in a 2D Matrix - I | Binary Search of 2D
15:42
take U forward
Рет қаралды 85 М.
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 11 МЛН