this is the code provided by TA https://ide.codingblocks.com/s/85149?_ga=2.99884698.547764522.1584019654-1071287290.1576385482
can you tell how this code is working for
input:
4
4 1 2 3
this code is giving 2 3 -1 -1
shoudn’t the output should be 2 3 4 -1
please resolve this
How this code is correct
You are right , this code fails on the test provided by you. You can rather try a very simple approach of checking the next greater element for each element.
Here is my code for reference : https://ide.codingblocks.com/s/196485
Hope it Helps.