Fatal error: control may reach end of non-void function

Next Greater Element II Leetcode



Please help me to solve this kind of error…

please share your code through ide.codingblocks.com

Sir,is this code visible to you through this link?

Yes, the code is visible can you tell me the name of the question.

Next Greater Element II Leetcode
my code is failing for similar elements.like second 1 in end returns -1
image

you’ve unnecessarily made the code complex, you just need to iterate the array twice using stack and you would get answer.

ohh.I will try implementing that.
Pr ab isko kaise theek kiya jaye. :sweat_smile:

sir ? ? ???

Sorry, the notification got messed up and I must’ve missed this one, can you explain the approach you are trying to use in order to solve this question


image
Sir, i tried following this approach for finding next greatest element.
now since given array is circular array so if we didnot find required greater element in end then we have to traverse from start of the array again.for dealing with circular array i am trying this.please correct me if am doing it wrong.

ohho yeh to bda hogya. :sweat:

instead of pushing the elements value inside the stack push the index of the element
Code

1 Like

Ohh. Thank you sir :slight_smile:

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.