Find Peak Element 🔥🔥| Leetcode 162 | C++ | Python | Medium | Approach + Code

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


Please like, share and subscribe if you found the video useful. Feel free to ask in comments section if you have any doubts. :)

#leetcode
#leetcodeJulyChallenge
#interviewpreparation
Find Peak Element solution
Find Peak Element Leetcode
Find Peak Element C++
Find Peak Element C++ Hindi
Find Peak Element Hindi

Checkout the series: 🔥🔥🔥

LIKE | SHARE | SUBSCRIBE 🔥🔥😊
Рекомендации по теме
Комментарии
Автор

What if the element in mid is smaller than both mid +1 and mid - 1 then the code will with bias first check for mid < mid+1 and move forward . Should that be a problem ??

hriyamdutta
Автор

Didi you are the best kya explain kiya aba baba ba kiraak acche se samajh aya thank you for explaining in details 🤙🤙❤️

ramdevbaba
Автор

Thank you Ayushi !!
but Can you please tell me why the following code of mine is giving me ERROR ?

class Solution {
public:
int findPeakElement(vector<int>& arr) {
int lo=0;
int hi=arr.size()-1;
int n=arr.size();

while(lo<=hi){
int mid=(lo+hi)/2;
if(mid>0 and mid<n-1){
if(arr[mid]>arr[mid-1] and arr[mid]>arr[mid+1]) return mid;
else if(arr[mid-1]>arr[mid]) hi=mid-1;
else lo=mid+1;
}
else{
if(mid==0){
if(arr[0]>arr[1]) return 0;
else return 1;
}
else if(mid==n-1){
if(arr[n-1]>arr[n-2]) return n-1;
else return n-2;
}
}
}
return lo;
}
};

vaibhavgupta
Автор

Didi low< high tak mein bhi hoon jayenga then return start

amulop