In the question of finding peak element, due to lack of time we were not able to see its implementation , whereas the algorithm (traversing entire array or using binary search(moving left when mid element is smaller than to its adjacent left element or moving right when mid element is smaller than to its adjacent right element) and checking peak element) proposed in video is correct and works perfectly fine atleast when all the elements are distinct in input array, provided the entire algorithm along with basic checks is implemented correctly, for one of the inputs(there could be many) {3 3 4 4 4 4} where values are duplicate in input array,if we go with the algorithm proposed in video there (will/may) be some issues, as we need to check for equality cases also while doing comparisons, so we need to modify the definition of peak element as the following : Correction : Let the input array "arr" be of length "n" and we have a variable "i" which is iterating on "arr" , so if (i > 0 and i < n) then, arr[i] is a peak element if (arr[i] >= arr[i-1] and arr[i] >= arr[i+1]) if (i == 0) then arr[i] is a peak element if (arr[i] >= arr[i+1]) if (i == n-1) then arr[i] is a peak element if (arr[i] >= arr[i-1]) ,please comment if you have any queries/doubts.
@enigma3683 жыл бұрын
1st problem - next smaller nearest to right 2nd problem - find peak element from array
@mukeshojha93183 жыл бұрын
First use pen and paper for thinking and dry run because I am beginning and i only know about all data structure and algorithm but not solve many problems and when I got new questions and try to solve on paper, it's like magic like after 20-30 minutes of thinking I am able to know that which DSA I should use to solve it. It works very well.
@Praveen-zq8ox3 жыл бұрын
Yes great approach
@prateekjain76233 жыл бұрын
How to praticipate in interview??
@srikanthsangani71213 жыл бұрын
It's seems he has already solved 1st question earlier I guess bcuz coming up with O(n) solution not even thinking for a minute is highly not possible.
@venugopalreddy85963 жыл бұрын
That's a basic question while doing stacks. So anyone can think of the solution in a matter of seconds if he's a DSA guy.
@devakash23 жыл бұрын
can't we just return minimum so far array in second question where he is asking about right to left. if minimum so far = self: return -1 else return minimum so far
@sarcasmtube693 жыл бұрын
see exp: 4 3 2 now for this acc to u min so far from right will be 2 and acc fo ur logic ans will be 2 2 -1 but actual ans is 3 2 -1 u want next smaller not the smallest on right..
@codeitclean18823 жыл бұрын
great..was really helpful
@high-oncode75763 жыл бұрын
Can we give interviews with beard and mustache
@BalajiVishnubhotla3 жыл бұрын
Next smaller to 7 is 5 not 1. Here 1 is the smallest element next to 7 but not smaller..
@Fcukrey3 жыл бұрын
The problem states next smaller i.e. it wants first element encountered on right which is smaller than current element
@avishekdutta29513 жыл бұрын
Too easy
@hiteshusingh85713 жыл бұрын
Very good interview
@shaikakber47173 жыл бұрын
Thank you
@mrgenius93963 жыл бұрын
OMG wht a Great Guy 🥵🥵🥵🥵🥵🥵Mar gaya🤣
@ShivamTiwari-ci2qg3 жыл бұрын
This person has good coding skills but less problem solving skill.