NEXT GREATEST ELEMENT : one test case not satisified

11
7 2 9 4 1 0 5 3 10 6 8
for this input
your code Output is
9 9 10 5 5 5 10 10 -1 8 -1

which is wrong
for 8 next greater element is 10 (because array is circular)

To find the next greater number for element Ai , start from index i + 1 and go uptil the last index after which we start looking for the greater number from the starting index of the array since array is circular.

https://ide.codingblocks.com/s/372788 INCORRECT OUTPUT

do not use int a[n];
because you did not know what is n at compile time so it is creating some random error and due to which n has changed to 4 abruptly
use this
int a[20000];

Modified Code

Okay! Thank you so much.