POTD- 01/03/2024 | Peak Element | Problem of the Day | GeeksforGeeks

preview_player
Показать описание
Welcome to the daily solving of our PROBLEM OF THE DAY with Yash Dwivedi. We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Data Structures and Algorithms but will also help you build up problem-solving skills.

So come along and solve the GFG POTD of 1st March 2024 with us!

Find daily solutions for POTD here on our channel! Make sure you are subscribed and stay updated.

-----------------------------------------------------------------------------------------


-----------------------------------------------------------------------------------------

Follow us and stay updated on everything happening in the world of geeks:

#GFGPractice #GeeksforGeeks #ProblemofTheDay #codingquestions #POTD #POTD1Mar #problemsolving #practice #dsa #PeakElement #YashDwivedi #gfgpractice #arrays #Searching
Рекомендации по теме
Комментарии
Автор

here array should be sorted right ? if we search for binary search ?

pankajsonagara
Автор

If we sort array then we have to check only two conditions even or odd length of array.

If even
Ele_pos=Length/2
Else
Ele_pos=( Length/2)+1

And like your code we seprate check for 1 length and 2 length array.

"If i made any mistake please correct me 😊"

ThomasShelby-sq
Автор

Good solution. You could initially set hi=n-2 instead of n-1, for the same reason you said lo was set to lo=1 and not 0. Also IMHO the while condition and the "return -1" are redundant, after all any array of integers does have a peak and thus it should be impossible for the program to ever get to the stage where lo>hi. Might as well use while(true) instead.

haha-uifp