BS-9. Find Peak Element

preview_player
Показать описание


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.

You can follow me across social media, all my handles are below:

0:00 Introduction of Course
Рекомендации по теме
Комментарии
Автор

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

takeUforward
Автор

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.

sayakghosh
Автор

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 )

anujrathore
Автор

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

ishanshah
Автор

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.

yashgarg
Автор

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

shivanshugarg
Автор

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

ankitdhattarwal
Автор

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

ritvikryadav
Автор

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

mriit
Автор

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.

GalaxyStart
Автор

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

iWontFakeIt
Автор

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

DeepikaKondamadugu
Автор

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

oguluribrahmaiah
Автор

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

ishangujarathi
Автор

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

girivardhanvelpula
Автор

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<int>& 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 <= high){
mid = low + (high - low)/2;

//Peak found
if(arr[mid-1] < arr[mid] && arr[mid] > 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;

}
};

theengineer
Автор

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

Dreamerlyf
Автор

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

graviton
Автор

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

viveksinghrajput
Автор

SUPERBBBB Explanation! Thankyou so much for your great efforts.

mahendrachourasiya