Find the greater number


Second test is not passing. Showing wrong answer.

Hello @ashish_meher,

This is happening for the test cases like:
4
1 2 3 2
Expected output:
2 3 -1 3
Your output:
2 3 3 -1

You have missed a very important part of question that array should be considered circular.

Hope, this would help.
Give a like, if you are satisfied.

Will you please elaborate how the output is 2 3 -1 3 for the example you have given?

Sure,

As the input array is:
1 2 3 2

  1. for 1, the first greater number on it’s left is 2

  2. for 2, it’s 3

  3. for 3, if we iterate toward right
    2 …no
    1…no (as array is circular)
    2…no
    -1 is answer (as we have iterated over all elements)

  4. for 2, if we iterate
    1…no
    2…no
    3…yes
    2 is answer.

Similaraly, for
5 5 5 5 5
Output is:
-1 -1 -1 -1 -1

Hope, this would help.

1 Like

I understood. Thank you

Expected output for:
5
1 2 3 2 5

??

The expected output would be:
for 1, 2
for 2, 3
for 3, 5
for 2, 5 //first greater number on right
for 5, -1

If you still have doubts, feel free to ask.

1 Like

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.