CODING GIVING ERROR.PLS CHECK

gfg question link- https://practice.geeksforgeeks.org/problems/next-larger-element-1587115620/1

code that i have written link- https://www.online-ide.com/UafRJz2nIG

i was solving ques on gfg link of the question havebeen attached above and the code i have written that link has been attached pls check the code and mark my mistakes

how long will it take to solve my doubt mam

for input like
11 13 21 3
you wont get answer as you forgot to add else if in line 22
also your approach wont pass all the test case due to tle
follow this:
Using Stack

  • Push the first element to stack.
  • Pick rest of the elements one by one and follow the following steps in loop.
    1. Mark the current element as next .
    2. If stack is not empty, compare top element of stack with next .
    3. If next is greater than the top element,Pop element from stack. next is the next greater element for the popped element.
    4. Keep popping from the stack while the popped element is smaller than next . next becomes the next greater element for all such popped elements
  • Finally, push the next in the stack.
  • After the loop in step 2 is over, pop all the elements from stack and print -1 as next element for them.