please check my code and point out my mistake.
Two test cases is not passing!
hello @Nikhil-Jettley-2567269533523013
why are u only looking for next element for next greater element. this is not correct
for example->
2 1 3
here next greater for 2 is 3 right?
same issue,i can’t able to understand the clearly.
please explain ,if possible.
to find the answer for ith index u need to iterate from index j={i+1 to n-1} , break the loop if u encounter any j which satisfy a[i] < a[j]
if u didnt get any such index then u need to look for left side array.
iterate from index j= {0,i-1} break the loop if u encounter any j which satisfy a[i] < a[j]
if u didnt get any index in left and right size then simply assign -1 value at index i
otherwise assign value at index j at index i
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.