Peak Element | O(logN) Time complexity and O(1) Space Complexity Solution |

  Рет қаралды 24,088

Hello World

Hello World

Күн бұрын

This is the video under the series of DATA STRUCTURE & ALGORITHM. We are going to solve Questions from GeeksforGeeks Majority Element in O(logN) Time Complexity and O(1) Space complexity. Given an array A of N integers. The task is to find a peak element in A in O( log N ).
An array element is a peak if it is not smaller than its neighbors. For corner elements, consider only one neighbor.
Which is a very famous and Routine question asked in Interview. The question is from the Topics Data structure. A full easy concept in Hindi. This is Question is asked in Many companies like Google, Amazon, Oyo Rooms, Paytm, Samsung, Adobe, etc..
We also Provide courses on Competitive Programming and Data structure. Please see our Full Playlist on our Channel.
----------------------------------------------------------------------------------------
► Homework Question: - - - - - - - - - - - - - - - - - - - -
----------------------------------------------------------------------------------------
► Peak Element: practice.geeks...
► PDF of Peak Element: github.com/Pri...
► CODE of Peak github.com/Pri...
----------------------------------------------------------------------------------------
*Follow me *
LinkedIn► / iamprince
Facebook► / helloworldofficials
Instagram► / helloworldbyprince
Twitter► / prince_king_
----------------------------------------------------------------------------------------
►Our Playlists on:-
►Competitive Programming : • How to start Competiti...
►C++ Full Course : • L-01 || Introduction a...
►Algorithms : • L-01 || Prefix Sum Arr...
►Data Structure: • Data Structures with C...
------------------------------------------------------------------------
Our Students Contacts Form:-
Form link: docs.google.co...
------------------------------------------------------------------------
#interview_preparation #geeksforgeeks #Hindi

Пікірлер: 74
@abinashchhetri5946
@abinashchhetri5946 Жыл бұрын
i have a tendency to see solution if i cant think of a solution for trying it for 5 to 10 min but after seeing your question explaination and your tendency to say the viewers to solve the question by themselves helped me and i just pause the video to solve the question and i could solve it in O(n) by myself now will look for log n solution that u explained thank you so much sir
@prakharsrivastava1860
@prakharsrivastava1860 3 жыл бұрын
Your voice is very calm and satisfying and best explaination of this question
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Ab main itna v aacha nahi hun 🤩🤩
@suhelali4547
@suhelali4547 2 жыл бұрын
@@HelloWorldbyprince aap achha ho apko pata nahi lekin aap achha ho bro!
@kapilgoel618
@kapilgoel618 3 жыл бұрын
Nicely explained "every independent array has one peak element" : )
@jatinmittal9184
@jatinmittal9184 2 жыл бұрын
You are simply awesome , I'm coming here after apna collage , aaditya Verma and many more . Here I'm able to understand concept . Subscriber++
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks brother Bass share kardo mere channel ko aap for motivating me ☺️
@rahul_singh_rajput3292
@rahul_singh_rajput3292 2 жыл бұрын
i solved this question but but i always review YT for more clarity.. how can i optime how other thinks.. and bhaiya apka Explanation 🔥🔥
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Always welcome Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@tusharshukla3871
@tusharshukla3871 Жыл бұрын
I saw many videos regarding y binary search in peak element that how to choose any sinlge part,but the way u explained is amazing
@vanshajdhar9223
@vanshajdhar9223 2 жыл бұрын
Hello, thanks for explaining the algorithm. I just have one scenario can you please check that [1,2,3,4,3,2,2,2,2,2,2]. Will binary search work for this scenario?
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
u can
@darshankubavat1764
@darshankubavat1764 3 жыл бұрын
Question aur explanation dono ek no.
@mayankverma5152
@mayankverma5152 3 жыл бұрын
best explaination from o(n) to o(logn) by covering all corner cases...
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Thanks buddy & Keep sharing
@icongrindsetsfj
@icongrindsetsfj Жыл бұрын
God bless you brother.
@MilindGupta
@MilindGupta 4 жыл бұрын
Expecting more nd more faang questions as there are very few good channels like you 🙂😊
@nishanttrivedi8711
@nishanttrivedi8711 Жыл бұрын
Thankyou sir now this question is crystal Clear to me you have explained very well
@motivationalshortvideos347
@motivationalshortvideos347 Жыл бұрын
amazing explanation
@vivekkejriwal3321
@vivekkejriwal3321 2 жыл бұрын
good explanation man.. saw 2-3 videos but everybody focused on code solution rather than discussing intuition. yours is good.
@cutejerry4273
@cutejerry4273 2 жыл бұрын
tremendous explanation ❤️ From Bangladesh
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks buddy Please, share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@FarmanOfficial777
@FarmanOfficial777 3 жыл бұрын
Bhai love your concer samajhne me der to lagi par maza aa gaya
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Nice 🙂 buddy
@ashuplayz4612
@ashuplayz4612 2 жыл бұрын
Thank uhhh brooooo...Nicely explainded. Subscribed
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Yeahhhh
@jeetsuchak1670
@jeetsuchak1670 Жыл бұрын
How can we implement binary search if the array is not sorted??
@HelloWorldbyprince
@HelloWorldbyprince Жыл бұрын
We can’t Binary search is applicable only in the sorted array
@adityasrivastava8196
@adityasrivastava8196 2 жыл бұрын
awesome explanation sir
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks for liking
@tusharnain6652
@tusharnain6652 2 жыл бұрын
The if condition 🔥🔥🔥
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
yess bro
@indianindian6001
@indianindian6001 2 жыл бұрын
Very nice explanation
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks 👍 Please, if possible then share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@aviralmishra181
@aviralmishra181 Жыл бұрын
Pehli baar kisi ko bolte suna ki "I hope video thoda km smjh aaya hoga" 🤣🤣 Pr ha smjh aa gya h
@ankushladani496
@ankushladani496 Жыл бұрын
Thank You Bhaiya...
@anjigolla4853
@anjigolla4853 Жыл бұрын
Superb explanation ❤
@aniruddhachunne3011
@aniruddhachunne3011 2 жыл бұрын
so nice.. i never realized that this question is one of the most important question
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
haan yaar aacha question hai
@Vedic_Wisdom_og
@Vedic_Wisdom_og 2 жыл бұрын
I swapped the condition inside the else if with else condition. Why am I getting error?
@akashnarvaria3663
@akashnarvaria3663 3 жыл бұрын
best explaination
@67_ujjwalsolanki78
@67_ujjwalsolanki78 Жыл бұрын
17:11 how 40 is peak element?
@rijishahuja8941
@rijishahuja8941 2 жыл бұрын
what if , we want to print all the peak elements , how can we write the code for this scenario
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
basically we have to store it or write down the print action when its calculated
@rijishahuja8941
@rijishahuja8941 2 жыл бұрын
@@HelloWorldbyprince yupp tried to store it in count and then later printed it, but was showing error, will try again though. Thank you for the revert though
@aniruddhachunne3011
@aniruddhachunne3011 2 жыл бұрын
sir on leete code it does not work... for all cases;
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
discuss page me dekho ek baar humlog kya galat kar rahe hai
@shreyaesha001
@shreyaesha001 2 жыл бұрын
thank you so much
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Glad it helped!
@YashSharm884
@YashSharm884 2 жыл бұрын
Superb
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Please, if possible then share this channel in your college, groups, or LinkedIn bcoz it's cost nothing to you 😀
@Ravikumar-ie3cw
@Ravikumar-ie3cw Жыл бұрын
Hi there, would anyone please explain to me how this question can be solved for the below test cases with the above logic: test case-1: array = {1, 7, 2, 3, 4, 5, 6} test-case-2: array = {1, 2, 3, 4, 5, 9, 7, 8} I would really appreciate your help
@itsaayush7357
@itsaayush7357 9 ай бұрын
Mujhe bs koi itna bta do ki O(logN) expected tc Diya hua he to bhaiya kh rahe h ki binary search lagega..pr binary search to sirf sorted array p lagta h na....to hum ese kese binary search laga sakte h?
@HelloWorldbyprince
@HelloWorldbyprince 9 ай бұрын
Ysss true But iss case me aap video fir se dekhkar dry run kijiye
@niteshshandilya4226
@niteshshandilya4226 2 жыл бұрын
thnx bhaiya
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
your welcome Nitesh
@praveenbabuveeranki5346
@praveenbabuveeranki5346 3 жыл бұрын
bro is the list sorted or not please clarify me
@aakashtiwari9505
@aakashtiwari9505 3 жыл бұрын
No
@102jayaprakashk2
@102jayaprakashk2 3 жыл бұрын
please add captions( english). I dont know Hindi .
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Yeah sure ☺️ but it will take bits of time for me Okay I will try to add it
@jayaprakashkumar4573
@jayaprakashkumar4573 3 жыл бұрын
@@HelloWorldbyprince Thank you
@amanahmed6057
@amanahmed6057 3 жыл бұрын
what if arr[ mid-1] arr[mid+1]........than what should we do????????/
@andiamakaza24
@andiamakaza24 3 жыл бұрын
Then mid is the peak element
@pawanshaw8639
@pawanshaw8639 3 жыл бұрын
sorry but i expected that after investing 20 mins ,i will get it but i did not happened,take it in a constructive way but your explanation needs to be more lucid
@HelloWorldbyprince
@HelloWorldbyprince 3 жыл бұрын
Soo polite 😁
@supriyamanna715
@supriyamanna715 Жыл бұрын
bro dekh, tu koi bhi sub array utha le, ek peak mil jayega, now taking the subarray thing is implemented using bsearch on the basis of the if condition bhaiya has explained in the vid, now the greedy selectino is to take the greater ele than mid at each iretation as it might be the case out there that o asani sai hi ban ja raha hai apna peak ele, moreover u can use ternamry search here in this qn
@saicharan4669
@saicharan4669 3 жыл бұрын
If u dont wanna go with any process , This question can be solved in one line of code : In python (inside function ) : "return arr.index(max(arr)) " That line of code is more than enough , just give it a try 😂😂
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Nice 🙂
@harshsaini1890
@harshsaini1890 2 жыл бұрын
bhai add bohot jayda ha
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thora to kamane do 😅😅
@fkcoder229
@fkcoder229 2 жыл бұрын
Check it for 10 9 2 17
@whatsappvideosandgifs4315
@whatsappvideosandgifs4315 3 жыл бұрын
I tried using this approach but it is showing time limit exceeded. int peakElement(int arr[], int n) { cin >> n; int low = arr[0], high = arr[n-1]; while(low low) && (mid < n-1)){ if(arr[mid] > arr[mid+1] && arr[mid] > arr[mid-1]){ return mid; } else if(arr[mid-1] > arr[mid]){ high = mid-1; } else { low = 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; } } } }
@WeStayAnonymous
@WeStayAnonymous 2 жыл бұрын
Epic explanation 🎊
@HelloWorldbyprince
@HelloWorldbyprince 2 жыл бұрын
Thanks asheesh
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 22 МЛН
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 79 МЛН
VAMPIRE DESTROYED GIRL???? 😱
00:56
INO
Рет қаралды 6 МЛН
小天使和小丑太会演了!#小丑#天使#家庭#搞笑
00:25
家庭搞笑日记
Рет қаралды 57 МЛН
BS-9. Find Peak Element
32:53
take U forward
Рет қаралды 186 М.
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 490 М.
Viral Video of a Man's Crazy Job Interview
16:02
Darryl Vega TV
Рет қаралды 1,3 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 453 М.
Peak Element | GeeksForGeeks | Placement & Interview | Easy | C++ Implementation
7:29
CodeMinati (Interview Code)
Рет қаралды 5 М.
BS-26. Find Peak Element-II | Binary Search
20:02
take U forward
Рет қаралды 83 М.
LeetCode Problem: 162. Find Peak Element | Java Solution
17:38
Code for Interview
Рет қаралды 864
Seja Gentil com os Pequenos Animais 😿
00:20
Los Wagners
Рет қаралды 22 МЛН