Why test cases are failing


here is the code

hi @hhiteshbansal_40d12e2460a1738e
refer this code -->

what is the reason of failing of two test cases

@hhiteshbansal_40d12e2460a1738e
ur logic is not fully correctā€¦ try to dry run my code for better understandingā€¦

yet not able to understand (mistake) what`s going wrong in my code

hi @hhiteshbansal_40d12e2460a1738e
your approach is incorrect
you are checking only next element

if (a[next] > a[curr]) {
    cout << a[next] << " ";
}

but greater element may not be just next
consider this example
5 4 6 3 10
Your output will be
-1 6 -1 10 -1
but Correct output is
6 6 10 10 -1

try to use stack hereā€¦ so kindly refer the code I sent aboveā€¦

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.