i’ve checked with most of the test cases according to me and all of them gives correct output…please help me to find why i m getting 1 test case out of 2 wrong…?
Find the greater element in array
Hi,
Since, you have to find next greater element you should change if(arr[i]<=arr[j]) to if(arr[i]<arr[j]).
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.
In the while loop you have used greater than equal to but problem asks for strictly greater.
Right condition is if(arr[i]<arr[j])
Also you can optimize your code using STACK, and traversing the array twice, once from left than from right.
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.