My Second test case doesn't pass. Whats the mistake?
Hello @Anchal,
’
This is happening for the test cases like:
4
1 2 3 2
Expected output:
2 3 -1 3
Your output:
2 3 -1 -1
You have missed a very important part of question that array should be considered circular.
Explanation:
As the input array is:
1 2 3 2
-
for 1, the first greater number on it’s left is 2
-
for 2, it’s 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) -
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.
Give a like, if you are satisfied.